Welcome Guest, Not a member yet? Register   Sign In
Controller name "List" doesn't work; "List2" works fine.
#1

[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.
#2

[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();
#3

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

[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-gui...uting.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
#5

[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.
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB