在cakephp中从数据库获取值时出错

在cakephp中从数据库获取值时出错,cakephp,Cakephp,我正在从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 ($sessionap

我正在从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>
function index()
    {
               $this->set('sessionapps', $this->Sessionapp->find('all'));
    }
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
但它不起作用,而且会出错

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如下

<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>
function index()
    {
               $this->set('sessionapps', $this->Sessionapp->find('all'));
    }
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

我想应该是这样

<?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; ?>


您是否尝试了我在您的视图文件中发布的答案。您没有正确引用数组元素。只需将foreach循环替换为我发布的循环。现在所有内容都显示了,但没有显示post列。您可以将数组$sessionapps粘贴到此处吗?@HarmeetKaur plz在编辑中查看该数组question@HarmeetKaur问题解决:)我正在用帖子代替尸体…@Usman ok。然后尝试打印(sessionapps);它给出了什么结果?@Usman查询$this->Sessionapp->find('all')没有给出结果。所以$sessionapps不包含要在视图文件中显示的元素