Config File is Double Loading - El Forum - 07-10-2012
[eluser]fjamal[/eluser]
Suddenly, for some reason, my application/config/config.php started loading twice.
I have the following code at the top of config file, starts from line 5 to line 12:
Code: function __autoload ($class) {
$file = APPPATH . 'libraries/' . $class . EXT;
if (strpos($class, 'CI_') !== 0) {
if (file_exists($file) && is_file($file)) {
@include_once (APPPATH . 'libraries/' . $class . EXT);
}
}
}
When i test a page, i get this error:
Code: Fatal error: Cannot redeclare __autoload() (previously declared in C:\xampp\htdocs\ci_centric\application\config\config.php:5) in C:\xampp\htdocs\ci_centric\application\config\config.php on line 12
If i wrap the autoload with Code: if(!function_exists('__autoload')) { ... }
, i get the following output:
Code: Notice: Constant FRONTEND_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 390
Notice: Constant FRONTEND_WEBPARTS_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 391
Notice: Constant FRONTEND_MAINPAGES_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 392
Notice: Constant BACKEND_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 393
Notice: Constant BACKEND_WEBPARTS_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 394
Notice: Constant BACKEND_MAINPAGES_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 395
Notice: Constant BACKEND_MAINPAGES_PATH already defined in C:\xampp\htdocs\ci_centric\application\config\config.php on line 396
.
.
.
Everything used to work fine for days; i just got the config double loading problem today.
Any help will be appreciated...
Config File is Double Loading - El Forum - 07-10-2012
[eluser]fjamal[/eluser]
Solved!
I defined BACKEND_MAINPAGES_PATH twice ... What a silly error ...
Config File is Double Loading - El Forum - 07-10-2012
[eluser]InsiteFX[/eluser]
Here is a newer spl_autoload
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
| to use '.php' now instead of EXT.
| 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;
}
}
});
Config File is Double Loading - El Forum - 08-01-2012
[eluser]fjamal[/eluser]
[quote author="InsiteFX" date="1341917574"]Here is a newer spl_autoload
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
| to use '.php' now instead of EXT.
| 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;
}
}
});
[/quote]
Thanks. Unfortunately, my host only supports PHP 5.2.*
Config File is Double Loading - El Forum - 08-01-2012
[eluser]InsiteFX[/eluser]
Then you need to use the older one here.
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 . 'php'))
{
include $file;
}
elseif (file_exists($file = APPPATH . 'libraries/' . $class . 'php'))
{
include $file;
}
}
}
|