I have a application/controller/login.php file containing the following
我有一个application / controller / login.php文件包含以下内容
class Login extends Controller {
function Login()
{
parent::Controller();
}
function index()
{
$this->mysmarty->assign('title', 'Login');
$this->mysmarty->assign('site_media', $this->config->item('site_media'));
$this->mysmarty->display('smarty.tpl');
}
}
My routes definition looks like the following:
我的路由定义如下所示:
$route['default_controller'] = "welcome";
$route['login'] = 'login';
$route['scaffolding_trigger'] = "";
The problem is that I keep getting a 404 when I try to access http://localhost/myapp/login. What did I do wrong? I've checked CI routes docs and cannot spot anything.
问题是当我尝试访问http:// localhost / myapp / login时,我一直收到404。我做错了什么?我已经检查过CI路线文档但无法发现任何内容。
3 个解决方案
#1
There shouldn't be anything wrong with this - does it work without the route? Also, have you set the .htaccess properly (i.e. does http://localhost/myapp/index.php/login work instead)
这应该没有任何问题 - 没有路线它是否有效?另外,您是否正确设置了.htaccess(即http://localhost/myapp/index.php/login是否正常工作)
#2
Another point to keep in mind, if you have have "enable_query_strings" set to true and aren't using the .htaccess mod_rewrite rules:
另外要记住的一点是,如果您将“enable_query_strings”设置为true并且未使用.htaccess mod_rewrite规则:
In config/config.php:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
The URL to route your request properly would look like this:
正确路由您的请求的URL如下所示:
http://localhost/myapp/index.php?c=login
#3
If you have not removed your index.php
from your app using the .htaccess
file, well thats another ball game on its own. But what you can do is this:
如果你还没有使用.htaccess文件从你的应用程序中删除你的index.php,这就是另一个自己的球类游戏。但你能做的是:
Set a default controller
that's not the welcome
file and if you want the welcome file to be your default use the link this way
设置一个不是欢迎文件的默认控制器,如果您希望将欢迎文件作为默认文件,请使用此链接
http://localhost/myapp/index.php/login
Remember this way only works when the index.php
file has not been removed using the .htaccess
file.
请记住,仅当使用.htaccess文件未删除index.php文件时,此方法才有效。
Also open the apllication/config/config.php
and use this code for the baseurl
同时打开apllication / config / config.php并将此代码用于baseurl
$config['base_url'] = 'http://localhost/myapp';
That should always do the trick.
这应该总能解决问题。
#1
There shouldn't be anything wrong with this - does it work without the route? Also, have you set the .htaccess properly (i.e. does http://localhost/myapp/index.php/login work instead)
这应该没有任何问题 - 没有路线它是否有效?另外,您是否正确设置了.htaccess(即http://localhost/myapp/index.php/login是否正常工作)
#2
Another point to keep in mind, if you have have "enable_query_strings" set to true and aren't using the .htaccess mod_rewrite rules:
另外要记住的一点是,如果您将“enable_query_strings”设置为true并且未使用.htaccess mod_rewrite规则:
In config/config.php:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
The URL to route your request properly would look like this:
正确路由您的请求的URL如下所示:
http://localhost/myapp/index.php?c=login
#3
If you have not removed your index.php
from your app using the .htaccess
file, well thats another ball game on its own. But what you can do is this:
如果你还没有使用.htaccess文件从你的应用程序中删除你的index.php,这就是另一个自己的球类游戏。但你能做的是:
Set a default controller
that's not the welcome
file and if you want the welcome file to be your default use the link this way
设置一个不是欢迎文件的默认控制器,如果您希望将欢迎文件作为默认文件,请使用此链接
http://localhost/myapp/index.php/login
Remember this way only works when the index.php
file has not been removed using the .htaccess
file.
请记住,仅当使用.htaccess文件未删除index.php文件时,此方法才有效。
Also open the apllication/config/config.php
and use this code for the baseurl
同时打开apllication / config / config.php并将此代码用于baseurl
$config['base_url'] = 'http://localhost/myapp';
That should always do the trick.
这应该总能解决问题。