2011-10-28 50 views
0

我为我的博客创建了函数,但它无法正常工作。 控制器:错误在哪里 - 它们显示不正确的消息

$id_get = Model::factory('index')->get_id($slug); 
$this->template->content = View::factory('index/article') 
        ->set('slug', $mysql_respnse) 
     ->set('commentars', Model::factory('index')->find_commentars($id_get)); 

查看:

<?php 
    if($commentars){ 
     echo 'There is a commentar!'; 
    } 
else{ 
echo 'There is no any commentar!'; 
} 
    ?> 

型号:

public function get_id($slug){ 
    $query = DB::query(Database::SELECT, 'SELECT id FROM ieraksti WHERE slug = :slug') 
      ->parameters(array(':slug' => $slug))->execute()->as_array(); 
} 

哪里错了吗?剧本显示'没有任何评论!',但我需要'有一个评论'。

+0

也许在您的数据库中没有评论? –

+0

我的数据库中有3条评论,其中artcl_id是3,博客文章ID是3. – reGative

+0

什么是'commentar'?你的意思是“评论”和“评论”或“评论”和“评论”? – Darsstar

回答

4

您不会在模型的get_id()方法中返回任何内容。因此,$ get_id的值为NULL,$ commentar也是。

+0

谢谢,模特是个错误,我1小时前纠正了这个错误。 :) – reGative