[英]CodeIgniter controller model 404 error
I'm getting a 404 error on my CodeIgniter site, I've had a look around at the other answers and playing with the .htaccess but yet to solve. 我在CodeIgniter网站上收到404错误,我已经查看了其他答案,并使用.htaccess进行播放,但尚未解决。 Its located on my domain.co.uk/admin 它位于我的domain.co.uk/admin
Controller - 控制器-
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Projects extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index() {
$this->load->model('project');
$data['projects']=$this->project->get_projects();
echo"<pre>";print_r($data['projects']);echo"</pre>";
}
}
Model - 型号-
<?php
class Project extends CI_Model{
function get_projects($num=10,$start=0){
$this->$db->select()->from('projects')->where('active',1)->order_by('date_added','desc')->limit($num,$start);
$query=$this->db->get();
return $query->result_array();
}
}
I've also added these routes - 我还添加了这些路线-
$route['default_controller'] = 'projects';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Currently have this .htaccess in my domain/admin folder 当前在我的域/管理员文件夹中有此.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Can anyone see why I might be getting a 404 error 谁能看到我为什么会收到404错误的信息
What do you have on your $route['default_controller']
variable? 您的$route['default_controller']
变量上有什么? (It shoulds be defined in \\application\\config). (应该在\\ application \\ config中定义)。
If you have $route['default_controller'] = "Projects"
, your index URL should be domain/admin/index.php/projects
or domain/admin/projects
* 如果您具有$route['default_controller'] = "Projects"
,则索引URL应该是domain/admin/index.php/projects
或domain/admin/projects
*
*You can easily remove this file by using a .htaccess file with some simple rules. *您可以通过使用.htaccess文件并按照一些简单规则轻松删除此文件。 Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items: 这是使用“负”方法的此类文件的示例,其中,除了指定的项目外,所有内容都被重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
$config['index_page'] = '';
On codeigniter 3 you should always have your first letter of your class and file name as upper case on models and controllers and libraries. 在codeigniter 3上,您应该始终在模型,控制器和库中以大写形式输入类和文件名的第一个字母。
Also I would rename projects model to Model_project.php because codeigniter may get confused if have same names. 我也将项目模型重命名为Model_project.php,因为如果使用相同的名称,codeigniter可能会感到困惑。
Model Model_project.php 模型Model_project.php
class Model_project extends CI_Model {
}
Controller Project.php 控制器Project.php
class Project extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('model_project');
}
}
You may need to set up your routes 您可能需要设置路线
http://www.codeigniter.com/user_guide/general/routing.html http://www.codeigniter.com/user_guide/general/routing.html
If you are using a codeigniter 3.0 then update your MODEL and CONTROLLER starting with capital letters and also don't give a same name for both model and controller as you have given in the above code. 如果您使用的是Codeigniter 3.0,则以大写字母开头更新您的MODEL和CONTROLLER,并且也不要像上面的代码那样给模型和控制器提供相同的名称。 For example: 例如:
class Projects extends CI_Controller {
//code comes here
}
In this Projects the name is absolutely fine but mark it that you file name should also start with capital letter that is Project.php Another for model: 在此项目中,名称绝对可以,但是请标记为文件名也应以大写字母开头,即Project.php。
class Projects_model extends CI_Model {
//code comes here
}
This is the way to make a proper way to work with codeigniter and also i have already told you that the MODEL and CONTROLLER filename must be started with the capital letter. 这是正确使用codeigniter的方式,而且我已经告诉过您,MODEL和CONTROLLER文件名必须以大写字母开头。
Thank You.. hope it will help you 谢谢..希望它将对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.