PHP用于从表'club'中选择并显示存储在“clubName”列下的所有记录的函数。 foreach语句($ club)返回未定义的变量错误。我错过了什么?
控制器:
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Club_Controller extends Template_Controller {
public $template = 'kohana/template';
public function index()
{
$this->template->title = 'All clubs';
$this->template->content = new View('allclubs');
$clubs = ORM::factory('club')->find_all();
$this->template->content->club = $clubs;
}
}
?>
查看:
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<div class="box">
<b><?php echo html::anchor('entry/form', 'add entry') ?></b><br>
<table cellpadding="10">
<?php foreach($clubs as $club): ?>
<tr>
<td align="left">
<?php echo html::anchor('entry/form/'.$club->id, 'edit') ?>
<?php echo html::anchor('entry/delete/'.$club->id, 'delete',
array('onclick'=>'return confirm("Are you realy realy want to do it?")')) ?>
</td>
<td align="left">
<?php echo $club->clubName ?>
</td>
</tr>
<?php endforeach ?>
</table>
</div>
答案 0 :(得分:0)
更改此
$this->template->content->club = $clubs;
到这个
$this->template->content->clubs = $clubs;