2017-07-26 96 views
0

我的codeigniter未显示页面。Codeigniter未显示数据,页面未显示

型号

function get_all_district_circulars() 
{ 

    $this->db->select('*'); 
    $this->db->from('district_circulars'); 
    $this->db->where('status', 1); 
    $this->db->order_by('id', 'desc'); 

    $query = $this->db->get(); 
    return $query->result(); 
} 

控制器指数函数

public function index() 
{ 
    $dt['dist_circulars'] = $this->content_model->get_all_district_circulars(); 
    $this->load->view('parts/top'); 
    $this->load->view('parts/header'); 
    $this->load->view('parts/nav'); 
    $this->load->view('district_circulars', $dt); 
    $this->load->view('parts/footer'); 
} 

查看

<?php 
    foreach($dist_circulars as $dt_circulars){ 
?> 
    <tr> 
     <td></td> 
    </tr> 
<?php 

    } 
?> 

如果我德尔ETE此foreach功能,页面能否正常显示,但如果我把它时,页面没有加载和显示This site can’t be reached和Chrome控制台显示GET http://localhost/anandadhara/district_circulars/ net::ERR_CONNECTION_RESET

我应该怎么办?

更新1

.htaccess如下

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase /anandadhara/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
</IfModule> 

我使用wampserver 2.2

更新2

我的文件名是district_circulars.php

CLASS

class District_circulars extends CI_Controller { 
public function __construct() 
{ 
    parent::__construct(); 

    $this->load->model('content_model'); 
} 

另一个更新

,如果我在这里显示一个结果,它工作正常。

<?php 
    foreach($dist_circulars as $dt_circulars){ 
?> 
    <tr> 
     <td><?php echo $dt_circulars->id; ?></td> 
    </tr> 
<?php 

    } 
?> 

但是,如果我表现出超过1场喜欢这里......

<td><?php echo $dt_circulars->id; ?></td> 
<td><?php echo $dt_circulars->memo_no; ?></td> 

或者,即使我把仅有的两个空白的HTML标签在这里...

<td></td> 
<td></td> 

页显示ERR_CONNECTION_RESET并显示页面为connection_reset的浏览器空白页,并显示无数据。

我不明白这里发生了什么。

+0

看来你错过了加载模式湖'$ this-> load-> model('content_model');' – jagad89

+0

不,我在我的模型中加载了'$ this-> load-> model('content_model');'in'public function __construct(){}' – Raj

+0

尝试'var_dump($ dt); die;'在'$ dt ['dist_circulars'] = $ this-> content_model-> get_all_district_circulars();'之后'。它可能会返回空。 – jagad89

回答

0

型号:

//需要使它成为一个公共职能,如果从控制器调用

public function get_all_district_circulars() 
{ 
//simplify your model call, use get instead of from 
return $this->db->select('*')->where('status', 1)->order_by('id', 'desc')->get('district_circulars')->result(); 


} 

查看:

地方的,如果检查,还可以使用在视图中,当PHP语法 http://php.net/manual/en/control-structures.alternative-syntax.php

<?php if(isset($dist_circulars)): ?> 

    <?php foreach($dist_circulars as $dt_circulars): ?> 


    <tr> 
     <td></td> 
    </tr> 

    <?php endforeach; ?> 

<?php endif; ?>