2017-02-09 166 views
0

我是Codeigniter的新手。Codeigniter 404 Page Not Found

我的数据库控制器

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
class Dbview extends CI_Controller{ 
     public function index() 
     //standard SQL Query 
     $sql = "SELECT * FROM 'news'", 
     $data['query_sql'] = $this->db->query($sql); 
     //active record query 
     $data['query_ar'] = $this->db->get('news'); 
     //load view 
     $this->load->view('dbview',$data);} 
?> 

我dbview鉴于

DB测试

<br /> 
<b>Standard SQL Query</b> <pre><?php print_r($query_sql->result_array()); ?>></pre> 
<br /> 
<b>Active Record Query</b> <pre><?php print_r($query_ar->result_array()); ?></pre> 

我设置数据库在phpMyAdmin,并把数据库信息到配置/数据库 当我尝试打开浏览器http://localhost/WeatherFinder/index.php/dbview 没有打开。最新错误还是我没有做过的事情? Thx

+0

如果它是一个完全白色的屏幕,请仔细检查你的数据库设置是否正确,也许在这里发布。 – coderodour

+0

是你的文件名Dbview.php只有第一个字母必须是大写,这里解释https://www.codeigniter.com/user_guide/general/styleguide.html#file-naming并且你也不需要关闭控制器https:// www.codeigniter.com/user_guide/general/styleguide.html#php-closing-tag – user4419336

+0

@coderodour,它不是白色,它的404页面未找到 找不到您请求的页面。 –

回答

1

我想我可能已经找到您的问题。正如下面的代码中指出并纠正的,您的索引函数缺少一个大括号。

<?php 
    defined('BASEPATH') OR exit('No direct script access allowed'); 

    class Dbview extends CI_Controller{ 

    public function index(){ // --- This opening brace missing maybe the issue. 

     //standard SQL Query 
     $sql = "SELECT * FROM 'news'", 
     $data['query_sql'] = $this->db->query($sql); 

     //active record query 
     $data['query_ar'] = $this->db->get('news'); 

     //load view 
     $this->load->view('dbview',$data); 
    } 
} 

你不需要从一个?>关闭您的控制器气馁。

+0

我上面的代码有一些缺点,应该现在工作。 – coderodour

+0

我得到了早些时候固定,仍然没有工作 –

+0

尝试按照这[链接]中的建议(http://stackoverflow.com/questions/7670561/how-to-get-htaccess-to-work-on-mamp ) – coderodour

0

谢谢大家试图帮助! 我认为我可能会发现问题。 它在我的模型文件中,我没有正确写出它。 我会稍后尝试修复它。 ,让你发布!

相关问题