CodeIgniter Forums
Controller name "List" doesn't work; "List2" works fine. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller name "List" doesn't work; "List2" works fine. (/showthread.php?tid=33000)



Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-11-2010

[eluser]itsdanieloconnor[/eluser]
Hey guys,

So I was getting a blank page when trying to create a super-simple controller "list.php."

Filename: list.php
Code:
<?php

class List extends Controller {

    function List()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('home_page');
    }
}


Filename: list2.php
Code:
<?php

class List2 extends Controller {

    function List2()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('home_page');
    }
}

That one works. ¿Qué?

I don't see "list" on the reserved list.


Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-11-2010

[eluser]JHackamack[/eluser]
List is a php function so you're probably running into conflicts there:
http://php.net/manual/en/function.list.php when you define it with the parent::Controller();


Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-11-2010

[eluser]itsdanieloconnor[/eluser]
Yeah, that must be the problem. Is there anyway to use .htaccess to show "list" when the controller name is "lists"?


Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-11-2010

[eluser]Unknown[/eluser]
As JHackamack said, list is a reserved keyword in PHP (http://www.php.net/manual/en/reserved.keywords.php) so it's most likely why you're having the problem. The solution is to use codeigniter's URI routing (http://ellislab.com/codeigniter/user-guide/general/routing.html). URI Routing will allow you to define a relationship between a URI path like 'list' and your controller... You can even use wildcards and regular expressions.

The route you'd want to define is really simple... just something like this:

Code:
$route['list'] = "lists";

where 'lists' is whatever you've used for your controller name


Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-12-2010

[eluser]itsdanieloconnor[/eluser]
Thanks! That fixes my problem. Maybe the Codeigniter team could add a mention of these reserved keywords on the CI reserved keywords page.


Controller name "List" doesn't work; "List2" works fine. - El Forum - 08-12-2010

[eluser]danmontgomery[/eluser]
http://www.php.net/manual/en/reserved.keywords.php