2010-03-18 102 views
0

我想学习codeigniter(下面的书),但不明白为什么网页出来空。codeigniter新手问题

我控制器

class Welcome extends Controller { 

    function Welcome() 
    { 
     parent::Controller(); 
    } 

    function index() 
    { 
     $data['title'] = "Welcome to Claudia's Kids"; 
     $data['navlist'] = $this->MCats->getCategoriesNav(); 
     $data['mainf'] = $this->MProducts->getMainFeature(); 
     $skip = $data['mainf']['id']; 
     $data['sidef'] = $this->MProducts->getRandomProducts(3, $skip); 
     $data['main'] = "home";  
     $this->load->vars($data); 
     $this->load->view('template'); 
    } 

的观点是:

<--doctype declaration etc etc.. --> 
</head> 
<body> 
    <div id="wrapper"> 
     <div id="header"> 
      <?php $this->load->view('header');?> 
     </div> 

     <div id='nav'> 
      <?php $this->load->view('navigation');?> 
     </div> 

     <div id="main"> 
      <?php $this->load->view($main);?> 
     </div> 

     <div id="footer"> 
      <?php $this->load->view('footer');?> 
     </div> 

    </div> 
</body> 
</html> 

现在我知道该模型是经过重新回到正确的变数,但页面出现完全空白。我希望至少看到一个错误,或基本的HTML结构,但页面只是空的。此外,即使我修改它,控制器也不起作用,如下所示:

function index() 
{ 
    echo "hello."; 
} 

我在做什么错? 一切工作,直到我对模型做了一些更改 - 但即使我删除所有这些新的更改,页面仍然是空白..我真的很困惑!

感谢, P.


我隔绝,让我的问题的功能。 那就是:

function getMainFeature() 
{ 
    $data = array(); 
    $this->db->select("id, name, shortdesc, image"); 
    $this->db->where("featured", "true"); 
    $this->db->where("status", "active"); 
    $this->db->orderby("rand()"); 
    $this->db->limit(1); 
    $Q = $this->db->get("products"); 
    if ($Q->num_rows() > 0) 
    { 
     foreach($Q->result_arry() as $row) 
     { 
      $data = array(
       "id" => $row['id'], 
       "name" => $row['name'], 
       "shortdesc" => $row['shortdesc'], 
       "image" => $row['image'] 
       ); 
     } 
    } 
    $Q->free_result(); 
    return $data; 
} 

我很确信,必须有一个语法错误的地方 - 但仍然不明白为什么它不显示任何错误,即使我已经设置了使用error_reporting E_ALL在索引函数..

+0

Q-> result_arry() - right是result_array()。 (或者它只是一个错字?) – DCrystal 2010-03-19 01:44:00

+0

well spotted :)这是代码中的一个实际错误,但是我已经发现它自己并没有解决问题.. – Patrick 2010-03-20 12:21:07

+0

如果你已经孤立到一个模型中的函数不要发布,所以我们可能会发现错误。 – Eric 2010-03-19 02:55:09

回答

2

第一个端口是在命令行上对您的控制器以及您更改并恢复的所有模型运​​行php -l。

% php -l somefile.php 

这可能是其中一个文件存在解析错误,并且您的php.ini中的显示错误设置为关闭。您应该将Display Errors设置为开发并关闭生产,以防尚未开发。

(编辑:。在上面你已经错过了断之类的收盘}的例子也许是)

+0

错误报告是= php.ini中的E_ALL。 我不熟悉命令行 - 我该怎么做? (缺少的括号只是一个剪切n粘贴错误..) 我已经在生成错误的模型之一中隔离了一个函数(例如,如果我拿出那个函数,控制器类的作品,即它输出“hello”;但是,模板没有加载,但没有出现错误!) – Patrick 2010-03-18 16:28:58

+0

无论您将error_reporting设置为什么,如果display_errors关闭,错误仍将不会显示在屏幕上。 – 2010-03-19 13:50:41

+0

谢谢,这解决了它。已经设置了display_errors,所以我能够看到错误并修复它! – Patrick 2010-03-19 18:34:41

1

确保使用error_reporting在index.php文件设置为E_ALL和发布您的代码为模型有问题。

通过你的功能看后,我怀疑它是由$this->db->orderby("rand()"); 对于活动的记录,则会导致这应该是$this->db->order_by('id', 'random');

注意orderby已被弃用,你仍然可以使用它,但现在新的函数名order_by

-1

不确定,但也可能由php的“display_errors”设置为false。 You can change it在您的php.ini文件中。

+0

投下来复制我的答案的一部分。 – 2010-03-19 13:53:21

+0

p.g.l.hall,对不起,我只是没有注意到它... – DCrystal 2010-03-19 14:03:42