php Codeigniter - 在此服务器上找不到请求的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13543779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter - the requested URL was not found on this server
提问by user927917
For the last couple of days my frustration has grown to new heights. Im trying to do a simple login system in codeigniter and I cant get it to work properly.
在过去的几天里,我的挫败感上升到了新的高度。我试图在 codeigniter 中做一个简单的登录系统,但我无法让它正常工作。
when submitting the login form I get the following error:
提交登录表单时,出现以下错误:
The requested URL /wishlist/login_controller/login was not found on this server.
在此服务器上找不到请求的 URL /wishlist/login_controller/login。
Here is the form:
这是表格:
<form method="post" action="<?php echo base_url()?>login_controller/login">
<input type="text"placeholder="E-mail" id="email" name="email">
<input type="password" placeholder="Password" id="password" name="password">
<input class="btn btn-primary span2" type="submit" id="sign-in" value="Sign In">
</form>
Here is my login function in login_controller:
这是我在 login_controller 中的登录功能:
class Login extends CI_Controller {
function login() {
$data['error'] = 0;
if ($_POST) {
$this->load->model('user_model');
$email = $this->input->post('email', true);
$password = $this->input->post('password', true);
$user = $this->user_model->login($email, $password);
if (!$user) {
$data['error'] = 1;
} else {
$this->session->set_userdata('userID', $user['userID']);
$this->session->set_userdata('firstname', $user['firstname']);
redirect(base_url().'admin_controller');
}
}
$this->load->view('home_view');
}
I'm using wampserver on localhost. Here is the url that it tries to access: localhost/wishlist/login_controller/login
我在本地主机上使用 wampserver。这是它尝试访问的 url:localhost/wishlist/login_controller/login
Am I correct in assuming that the first part after base_url() is the controller and the second part is the function in that controller?
假设 base_url() 之后的第一部分是控制器而第二部分是该控制器中的功能,我是否正确?
A couple of settings from the config folder.
配置文件夹中的一些设置。
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$route['default_controller'] = "site_controller";
回答by itsme
please rename your controller from
请重命名您的控制器
class Login extends CI_Controller {
to
到
class Login_Controller extends CI_Controller {
then you can do
那么你可以做
<form method="post" action="<?php echo site_url('login_controller/login'); ?>">
<input type="text"placeholder="E-mail" id="email" name="email">
<input type="password" placeholder="Password" id="password" name="password">
<input class="btn btn-primary span2" type="submit" id="sign-in" value="Sign In">
</form>
then use this:
然后使用这个:
$config['base_url'] = 'http://localhost/wishlist/';
$config['index_page'] = '';
and htacees:
和 htacees:
RewriteEngine On
RewriteBase /wishlist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wishlist/index.php/ [L]
if it's not enought switch config.php file at line:
如果还不够,请在以下行切换 config.php 文件:
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
i use AUTO maybe you need QUERY_STRING or REQUEST_URI option
我使用 AUTO 也许你需要 QUERY_STRING 或 REQUEST_URI 选项
回答by Pankaj Khairnar
Change your login() method to something like user_login as using the same name for class and method is not right if you are not using that method as a constructor .
将您的 login() 方法更改为类似 user_login 的方法,因为如果您不将该方法用作构造函数,则对类和方法使用相同的名称是不正确的。
Try to access your url like this
尝试像这样访问您的网址
http://localhost/wishlist/index.php/login/user_login
as you have not change any stting and not added htaccess file your code should be accesible normally so codeiginter has a pattern of accessing url like
由于您没有更改任何设置并且没有添加 htaccess 文件,您的代码应该可以正常访问,因此 codeiginter 具有访问 url 的模式,例如
http://localhost/folder_name/index.php/controller_name/method_name
and it seems your accessing URL is not correct.
并且您的访问网址似乎不正确。
回答by Narf
You have 2 problems at the same time:
你同时有两个问题:
Your form points at 'login_controller', while your controller is called 'login' (this has already been answered).
You must nothave a method named in the same way as your controller.
Such method (unless your class is within a namespace, but that's not the case with CodeIgniter) is executed as the class constructor.
您的表单指向“login_controller”,而您的控制器称为“login”(这已经得到了回答)。
您不能使用与控制器相同的方式命名的方法。
此类方法(除非您的类位于命名空间内,但 CodeIgniter 并非如此)作为类构造函数执行。
回答by kaseOga
You call action="<?php echo base_url()?>login_controller/login">when controller's name is "login"and method "login".
您action="<?php echo base_url()?>login_controller/login">在控制器名称为"login"and时调用method "login"。
You need to call
base_url('login/login');and sure, set base_urlin config.php, you have index_page setted.
您需要调用
base_url('login/login');并确定,设置base_urlin config.php,您已经设置了 index_page 。
Maybe you dont have .htaccess, then you need to call mysite.com/index.php/login/login/
也许你没有.htaccess,那么你需要打电话mysite.com/index.php/login/login/

