我尝试使用kohana框架,但我有一个小问题,当我试图从我的数据库表检索单个记录。我的表:
ads
id_ads
title_ads
description_ads
我的控制器:
public function action_single()
{
$ads_id = $this->request->param('id_ads');
$ads = ORM::factory('ads', $ads_id);
$view = new View('ads/single'); // load the view/ads/single.php
$view->set('ads', $ads); // set 'ads' object to view
$this->template->set('content', $view);
}
我的观点
<h2><?php echo $ads->title_ads; ?></h2>
<pre><?php echo $ads->description_ads; ?></pre>
当我去到localhost/kohana/index.php/ads/single/1浏览器显示什么,问题在哪里?
try this:
$ads_id = $this->request->param('id_ads');
$ads =ORM::factory('ads'->find($ads_id);
或
$ads_id = $this->request->param('id_ads');
$ads =ORM::factory('ads')->where("id","=",$ads_id)->find();
传递参数,我认为,是更好(更容易)扩展Controller_Template以这种方式:
class Controller_News extends Controller_Template{
...
public function action_single()
{
...
$view->ads=$ads;
$this->template->content = $view;
}
}