这是我的第一个 php 框架。我的控制器中有一个 php 文件,即 posts.php,但是当我尝试运行它 localhost/codeigniter/index.php/posts 时,它显示错误 404
应用程序文件夹内的.htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
自动加载.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
配置文件
$config['base_url'] = 'http://localhost/codeigniter/';
$config['index_page'] = 'index.php';
路线.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
模型文件夹中的 post.php
class Post extends CI_Model{
function get_posts($num = 20, $start = 0){
//$sql = "SELECT * FROM users WHERE active=1 ORDER BY date_added DESC LIMIT 0,20;";
$this->db->select()->from('posts')->where('active', 1)->order_by('date_added', 'desc')->limit(0, 20);
$query=$this->db->get();
return $query->result_array();
}
}
控制器文件夹中的 posts.php
class Posts extends CI_Controller{
function index(){
$this->load->model('post');
$data['posts'] = $this->post->get_posts();
echo "<pre>";
print_r($data['posts']);
echo "</pre>";
}
}
它应该显示一个空数组,但它显示错误 404