【问题标题】:Kohana CRUD: Undefined VariableKohana CRUD:未定义的变量
【发布时间】:2013-12-04 02:38:30
【问题描述】:

PHP 函数从表“clubs”中选择并显示存储在“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>

【问题讨论】:

    标签: php undefined kohana kohana-orm


    【解决方案1】:

    改变这个

    $this->template->content->club = $clubs;
    

    到这里

    $this->template->content->clubs = $clubs;
    

    【讨论】:

      猜你喜欢
      • 2011-06-11
      • 2021-02-27
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      相关资源
      最近更新 更多