【发布时间】:2016-04-15 07:34:28
【问题描述】:
我正在使用来自 Internet 的非常简单和基本的示例来研究 Kohana 3.3。
我的控制器:
类 Controller_Index 扩展 Controller_Template {
public $template='v_index';
public function action_index()
{
$this->template->title='Online store';
$this->template->content='Homepage';
}
public function action_catalog()
{
$title='Products catalog';
$products = array(
'Product 1'=>100,
'Product 2'=>200,
);
$this->template->title='Online products store';
$this->template->content=View::factory('v_catalog')
->bind('products',$products)
->bind('product',$product)
->bind('cost',$cost)
->bind('title',$title);
}
}
我的观点 v_index.php
<h1><?=$title;?></h1>
<hr>
<p><?=$content;?></p>
我的观点v_catalog.php:
<h2><?=$title?></h2>
<? foreach ($products as $product=>$cost): ?>
<p><?=$product?><strong><?=$cost?></strong></p>
<? endforeach; ?>
当我转到http://localhost/kohana/index/catalog 时,浏览器会输出两个标题:在线商店和产品目录 ok。但是在 foreach 圆圈所在的地方,它会输出
$cost): ?>
我做错了什么?我不能遍历这个数组吗?或者我的语法错误?希望能帮助我解决我的错误。
【问题讨论】:
标签: kohana kohana-3.3