Trying to make a CodeIgniter controller called “List”

人走茶凉 提交于 2019-12-22 06:03:26

问题


I have the following code in controllers/list.php:

<?php
class List extends Controller { 
    function index()
    {
        echo "hi";
    }
}
?>

However, trying to access it gives me the following PHP error:

Parse error: syntax error, unexpected T_LIST, expecting T_STRING in /var/www/sitename/htdocs/system/application/controllers/list.php on line 3

Renaming the file to "example.php" and replacing "class List" with "class Example" works perfectly fine... my first thought was maybe "List" was a reserved name, but I checked CI's list of reserved names here and it's not there.

I know I could fix the problem by just calling the thing something else but I really want my controller to be called "list" if at all possible. Any ideas, or insight into why this is happening?

Thanks,
Mala


回答1:


list is a reserved word in PHP, so you'll have to use something else. You can probably use a custom route to change the url if you really need to.




回答2:


list is a built-in php construct



来源:https://stackoverflow.com/questions/2014524/trying-to-make-a-codeigniter-controller-called-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!