-1

我从我的 cakephp 应用程序中的表 sessionapps 中获取值。

我有 index.ctp 文件如下

<table>
<tr><td>ID</td><td>Title</td><td>Post</td><td>Actions</td><td>Created On</td></tr>
<?php foreach ($sessionapps as $post): ?>
<tr><td><?php echo $post[Sessionapp][id];?></td>
    <td><?php echo $data->Html->link($post[Sessionapp][title],array('controller'=>'sessionapp','action'=>'view',$post[Sessionapp][id]));?></td>
    <td><?php echo $post[Sessionapp][post];?></td>
    <td><?php echo $this->Html->link('Edit Post ', array('action' => 'editarticle', $post[Sessionapp][id]));?></td>
    <td><?php echo $post[Sessionapp][created];?></td></tr>
<?php endforeach; ?>
</table>

我已经创建了它的控制器 sessionapps_controller.php 并在其中添加了操作索引,如下所示

function index()
    {
               $this->set('sessionapps', $this->Sessionapp->find('all'));
    }

但它不起作用并给出错误

Notice (8): Use of undefined constant Sessionapp - assumed 'Sessionapp' [APP/views/sessionapps/index.ctp, line 14]

Notice (8): Use of undefined constant id - assumed 'id' [APP/views/sessionapps/index.ctp, line 14]

我的数组 $sessionapps 如下

Array ( [0] => Array ( [Sessionapp] => Array ( [id] => 1 [title] => The title [body] => This is the post body. [postby] => [created] => 2013-01-15 11:35:13 [modified] => ) ) [1] => Array ( [Sessionapp] => Array ( [id] => 2 [title] => A title once again [body] => And the post body follows. [postby] => [created] => 2013-01-15 11:35:13 [modified] => ) ) [2] => Array ( [Sessionapp] => Array ( [id] => 3 [title] => Title strikes back [body] => This is really exciting! Not. [postby] => [created] => 2013-01-15 11:35:13 [modified] => ) ) ) 1
4

1 回答 1

1

我认为应该是这样的。

<?php foreach ($sessionapps as $post): ?>
<tr><td><?php echo $post['Sessionapp']['id'];?></td>
    <td><?php echo $data->Html->link($post['Sessionapp']['title'],array('controller'=>'sessionapp','action'=>'view',$post['Sessionapp']['id']));?></td>
    <td><?php echo $post['Sessionapp']['post'];?></td>
    <td><?php echo $this->Html->link('Edit Post ', array('action' => 'editarticle', $post['Sessionapp']['id']));?></td>
    <td><?php echo $post['Sessionapp']['created'];?></td></tr>
<?php endforeach; ?>
于 2013-01-15T07:01:20.217 回答