database - retrieve single record with kohana 3.3 with request->param() is NULL -
i try use kohana framework have little issue wen try retrieve single record table of database. table:
ads id_ads title_ads description_ads
my controller:
public function action_single() { $ads_id = $this->request->param('id_ads'); $ads = orm::factory('ads', $ads_id); $view = new view('ads/single'); // load view/ads/single.php $view->set('ads', $ads); // set 'ads' object view $this->template->set('content', $view); }
my view
<h2><?php echo $ads->title_ads; ?></h2> <pre><?php echo $ads->description_ads; ?></pre>
when go to localhost/kohana/index.php/ads/single/1 browser display nothing, problem?
try this:
$ads_id = $this->request->param('id_ads'); $ads =orm::factory('ads'->find($ads_id);
or
$ads_id = $this->request->param('id_ads'); $ads =orm::factory('ads')->where("id","=",$ads_id)->find();
to pass parameters, think, better (easier) extend controller_template in way:
class controller_news extends controller_template{ ... public function action_single() { ... $view->ads=$ads; $this->template->content = $view; } }
Comments
Post a Comment