Welcome Guest, Not a member yet? Register   Sign In
Can we extend our own core classes
#11

[eluser]Aken[/eluser]
If you add the Frontend_Controller class to the MY_Controller.php file, does it work? CI doesn't know to include that file, since there is no auto-load. It's only set up to load MY_Controller. You can put all of your base controllers in that one file, though. Or add a normal PHP include/require if you prefer to split them up.
#12

[eluser]codeigniterzzz[/eluser]
[quote author="Aken" date="1352418795"]If you add the Frontend_Controller class to the MY_Controller.php file, does it work? CI doesn't know to include that file, since there is no auto-load. It's only set up to load MY_Controller. You can put all of your base controllers in that one file, though. Or add a normal PHP include/require if you prefer to split them up.[/quote]

So what ur suggesting is something like this:

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

include('Frontend_Controller.php');
class MY_Controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }
}
?>

#13

[eluser]codeigniterzzz[/eluser]
actually aken ur right, i literally have to include the Frontend_Controller in the same file as MY_Controller. Then I can extend it...The luckyfella was right, i was for some reason assuming i can place each controller extending MY_Controller in separate files...
#14

[eluser]CroNiX[/eluser]
Not if you create an autoloader.
http://ellislab.com/forums/viewthread/218183/
#15

[eluser]LuckyFella73[/eluser]
Quote:Not if you create an autoloader.
http://ellislab.com/forums/viewthread/218183/

My fault, I forgot to mention that ... I allways use a
prepared config.php when starting a new project so I
missed that one.

@codeigniterzzz
I would prefer to use this autoload instead of manually
include the classes.

If you have PHP 5.3+ installed use this one (Phil Sturgeon and Kenneth Vogt):
Code:
/*
| -------------------------------------------------------------------------
| Native spl_autoload_register() - by Kenneth Vogt
| -------------------------------------------------------------------------
|
| Here is an updated version of Phil Sturgeon’s code:
|
| Thanks to Phil Sturgeon and Kenneth Vogt.
|
| NOTE:
| Requires PHP 5.3.+
| As of CI 3.0 Dev - The constant EXT has been removed modified
| should work for all version of CI and PHP 5.3
|
| Place at the bottom of your ./application/config/config.php file.
| -------------------------------------------------------------------------
*/
spl_autoload_register(function($class)
{
if (strpos($class, 'CI_') !== 0)
{
  if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
  {
   include $file;
  }
  elseif (file_exists($file = APPPATH . 'libraries/' . $class . '.php'))
  {
   include $file;
  }
}
});

Otherwise this one (Phil Sturgeon):
Code:
/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }
        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}

Place it at the bottom of application/config/config.php




Theme © iAndrew 2016 - Forum software by © MyBB