Closed it-can closed 11 years ago
Does your controller file happen to be named 'Index.php' instead of 'index.php'?
controller is named index.php
I use also MY_Controller that extends CI_Controller, a quick view in the code I suspect that the problem is somewhere in this?
index.php
class Index extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('includes/template', array('data'=>'123'));
}
}
MY_Controller.php
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->vars(array('version'=>123));
}
}
OK, the root of the "problem" is an is_callable
check in system/core/CodeIgniter.php: https://github.com/EllisLab/CodeIgniter/commit/38e32f643492a7bf0233bb9848138d183fbdfcd4#L0R298
And the reason that it returns FALSE is something that many people (you included) would consider a bug, but it's NOT: https://bugs.php.net/bug.php?id=62208&edit=1
Now, you'd probably want to revert the latest changes and decide to not use is_callable()
(or to use is_callable(array(new $class, $method))
), but here's why it shouldn't be done ...
$ cat test.php
<?php
class Index {
public function __construct()
{
echo "foo\n";
}
public function index()
{
echo "bar\n";
}
}
new index();
$ php test.php
foo
So far so good - it would work as expected, for you. But consider somebody that doesn't override __construct()
:
$ cat test.php
<?php
class Index {
public function index()
{
echo "bar\n";
}
}
new index();
$ php test.php
bar
... their index()
method will be considered a constructor and that's a very nasty false-positive.
The conclusion is something that is never mentioned in the docs, but is known to everybody who has ever used PHP 4 - you should never use a matching class->method
pair.
okay didn't know that... I changed the index method to start() and changed the default route to index/start...
seems to work now... Thanks
Thanks narfbg.. I had a issue with this 404 error. your answer helped :+1:
I am getting a "404 Page Not Found The page you requested was not found." error when I go to my site: www.test.com
I have a the following routes.php
I use also MY_Controller that extends CI_Controller, a quick view in the code I suspect that the problem is somewhere in this?
Urls with www.test.com/page/test-page seems to work. But the default page (just www.test.com) shows a 404. This worked before...