Welcome Guest, Not a member yet? Register   Sign In
Extending from my own controller
#21

[eluser]Alface[/eluser]
[quote author="Phil Sturgeon" date="1273072843"][quote author="Alface" date="1273058408"]It show me this:
Fatal error: Class 'Test' not found in C:\xampplite\htdocs\projetos\forsite\system\application\controllers\test2.php on line 3

PHP Version 5.2.8[/quote]

Did you add the __autoload()? It's not found because you haven't told PHP how to find it.[/quote]

I add, what could it be?
#22

[eluser]Phil Sturgeon[/eluser]
[quote author="Alface" date="1273074100"]I add...[/quote]

Ahh, well isn't that useful and descriptive. Using my powers of mental-remote PHP debugging I reckon... your rotary widgets are partially misaligned. Try re-polarizing them and point them west.
#23

[eluser]Alface[/eluser]
[quote author="Phil Sturgeon" date="1273074216"][quote author="Alface" date="1273074100"]I add...[/quote]

Ahh, well isn't that useful and descriptive. Using my powers of mental-remote PHP debugging I reckon... your rotary widgets are partially misaligned. Try re-polarizing them and point them west.[/quote]

Sorry friend, I don't know what to say.. it is so simple...

I add this code at the end of the file application/config/config.php
Code:
function __autoload($class){
    if (file_exists(APPPATH."controllers/".strtolower($class).EXT))
    {
            require_once(APPPATH.'controllers/'.strtolower($class).EXT);
    }
}

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

class Test extends Controller {

    function __construct()
    {
        parent::__construct();
    }

}

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

class Test2 extends Test {

    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        echo 'hello';
    }
}



I access the url http://localhost/index.php/test2
and shows this:
Code:
Fatal error: Class 'Test' not found in C:\xampplite\htdocs\projetos\forsite\system\application\controllers\test2.php on line 3

Is this wrong? o.o
#24

[eluser]n0xie[/eluser]
Are you sure your __autoload is called?

Please test this:
Code:
function __autoload($class){
    echo $class;
    exit();
    if (file_exists(APPPATH."controllers/".strtolower($class).EXT))
    {
            require_once(APPPATH.'controllers/'.strtolower($class).EXT);
    }
}
#25

[eluser]Alface[/eluser]
[quote author="n0xie" date="1273502891"]Are you sure your __autoload is called?

Please test this:
Code:
function __autoload($class){
    echo $class;
    exit();
    if (file_exists(APPPATH."controllers/".strtolower($class).EXT))
    {
            require_once(APPPATH.'controllers/'.strtolower($class).EXT);
    }
}
[/quote]


I don't think so.. but why?

I recived it:
Code:
Fatal error: Class 'Test' not found in C:\xampplite\htdocs\projetos\forsite\system\application\controllers\test2.php  on line 3
#26

[eluser]ladooboy[/eluser]
Not sure if that helps, but I've did the following:

Quote:class MY_Controller extends Controller{ // base controller
function __construct(){
parent::Controller();
}
}

class Login extends MY_Controller{ //extends base controller
function __construct(){
parent::__construct
}
}

where you put the MY_Controller class into the Libaries folder. In this way the MY_Controller get always loaded.
#27

[eluser]Chandana Bandara[/eluser]
Thank you. You guys saved my day.
Keep up the good work, and rock the world!!
Cheers.
#28

[eluser]Chandana Bandara[/eluser]
This worked in my localhost. But when I deployed it in Godaddy it gave me the old error that class not found :long:


Any clue??

Thanks
#29

[eluser]Chandana Bandara[/eluser]
[quote author="Chandana Bandara" date="1295751668"]This worked in my localhost. But when I deployed it in Godaddy it gave me the old error that class not found :long:


Any clue??

Thanks[/quote]

Found the problem,
My localhost is Windows and Godaddy is Linux.
I was missing the strtolower in the config function.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB