Codeigniter控制器不起作用 [英] Codeigniter Controller is not working
问题描述
我是Codeigniter的新手,有点困惑我的调节器没有拿起我的控制器,我的控制器Practice.php和代码是:
I am new in codeigniter and bit confused My conditioner is not pickup my Controller, My controller practice.php and code is:
class Practice extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
function foo()
{
echo 'Hello world';
}
function index()
{
echo 'Hello index';
}
}
我正在尝试像Localhost / foldername /一样加载它练习/ foo。它应该工作为什么不呢?
I am trying to load it like Localhost/foldername/practice/foo . its suppose to work why not?
谢谢。
注意:实践也是我没有控制器名称索引功能的默认控制器的运行方式类似于localhost / foldername /将显示索引函数结果。
Note : Practice is also my default controller without contoller name index function is working like localhost/foldername/ will show the index function result.
推荐答案
CodeIgniter说:
CodeIgniter says:
默认情况下,index.php文件将包含在您的URL中:
By default, the index.php file will be included in your URLs:
example.com/ index.php / news / article / my_article
example.com/index.php/news/article/my_article
尝试使用此版本访问它
localhost/foldername/index.php/practice/foo
如果要在没有index.php的情况下访问它,则应在根目录中创建一个.htaccess文件,并将此代码放置:
If you want to access it without the index.php, you should create a .htaccess file in your root directory and place this code:
RewriteEngine On
RewriteEngine On
RewriteBase /foldername/
# If your project is in server root then should be: RewriteBase /
# If your project is in folder then it should be: RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
请参见 CodeIgniter网址
这篇关于Codeigniter控制器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!