Welcome Guest, Not a member yet? Register   Sign In
Creating and using libraries
#13

[eluser]bretticus[/eluser]
Okay, maybe two bad apples. Personally, I didn't care for your attitude. It appeared to me that people were taking the time to give you good advice and you quickly discounted it or argued with it. I apologize for giving you a hard time but know that your good attitude also counts. Especially when you are asking for people to help you. That said...

Here is a way to use __autoload() in codeigniter. It's a simple hack but it complies with the Codeigniter framework standard (well not the php4 compatibility issue but most people should not have to use PHP4 anymore) and should work the way you'd prefer it to work.

This is done using plugin support for CI.

1. Create an autolib folder (or your preferred name) under application/.

2. Add autoload_pi.php to your system/plugins folder.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function __autoload($class_name) {
    $path = APPPATH . 'autolib/' . $class_name . '.php';
    if ( file_exists($path) )
        require_once $path;
}

3. Add your Menu class to application/autolib. Name it Menu.php.

4. Add autoload to plugins under application/config/autoload.php.

Code:
/*
| -------------------------------------------------------------------
|  Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
|    $autoload['plugin'] = array('captcha', 'js_calendar');
*/

$autoload['plugin'] = array('autoload');

5. Call $menu = new Menu(); anywhere in codeigniter and instantiate as many times as you'd like.


Messages In This Thread
Creating and using libraries - by El Forum - 09-30-2009, 04:09 PM
Creating and using libraries - by El Forum - 10-01-2009, 07:11 AM
Creating and using libraries - by El Forum - 10-01-2009, 08:44 AM
Creating and using libraries - by El Forum - 10-01-2009, 02:13 PM
Creating and using libraries - by El Forum - 10-01-2009, 02:38 PM
Creating and using libraries - by El Forum - 10-01-2009, 02:49 PM
Creating and using libraries - by El Forum - 10-01-2009, 02:58 PM
Creating and using libraries - by El Forum - 10-01-2009, 03:04 PM
Creating and using libraries - by El Forum - 10-01-2009, 03:47 PM
Creating and using libraries - by El Forum - 10-01-2009, 04:03 PM
Creating and using libraries - by El Forum - 10-01-2009, 05:29 PM
Creating and using libraries - by El Forum - 10-01-2009, 08:02 PM
Creating and using libraries - by El Forum - 10-01-2009, 08:22 PM
Creating and using libraries - by El Forum - 10-06-2009, 12:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB