我想在另一个控制器中实例化一个从购物篮中获取内容的 kohana 控制器函数。
换句话说,在我拥有的一个控制器中(在 basket.php 中)
public function action_index()
{
$basket = $this->basket;
$contents = $basket->contents->find_all();
$this->view->basket = $basket;
$this->view->contents = $contents;
}
我想在其他控制器 sale.php 中调用此函数,因为我希望购物篮中已经存在的产品在列表中以某种方式标记。我想在实际列出产品的控制器 sale.php 中调用此函数。
我在 sale.php
公共函数 action_browse($id, $category_id = NULL) {
$sale = Model::factory('sale')->active()->find($id);
$basket_content = $this->user->get_basket($sale);
if ( ! $sale->loaded())
{
throw new Kohana_Request_Exception('Sale not found.');
}
if (isset($category_id))
{
$category = $sale->categories->find($category_id);
if ( ! $category->loaded())
{
throw new Kohana_Request_Exception('Category not found.');
}
$products = $sale->products->category($category_id)->find_all();
$this->view->category = $category;
}
else
{
$products = $sale->products->find_all();
}
谢谢!