2013-08-03 45 views
0

在我的UsersController的索引操作中,我想传递字符串和数组来查看,这样我的View就可以正确呈现。我不知道我在做什么错,但我的视图文件没有得到我的数组之一来查看。无法传递数组以查看cakephp 1.3版

$users = $this->User->getUsers(); 

//Setting all variable that are present in layout 
$this->set('title_for_layout','Users - Admin'); 
$page_headings = array("text" => "Users", "clss" => "icon-head"); 
$this->set('page_heading', $page_headings); 
//Ends here 

//This is actually going to action view file    
$this->set(compact('users')); 

我的视图文件中的代码是这样的

<div><?php echo $page_heading[0]['text']; ?></div>

<?php foreach($users as $user){ ?>

我能够得到$用户变量这里,但注意到越来越$ page_heading。

我得到这个错误Undefined variable: page_heading

我已经试过各种这样的:

$this->set($page_headings);

$this->set(compact('page_headings');

是的,我已经在上面的代码后做的还可以查看文件改变我的变量名page_headings。我无法让它工作。可以请任何人帮忙。

在此先感谢。

+0

而且'title_for_layout'也被提交了吗?它应该没有什么区别,但是如何使用一个集合调用'$ this-> set(compact('title_for_layout','page_heading','users'));'? – ndm

+0

你的''title_for_layout'来了不错..我试着把数组变量放在一起'$ this-> set(compact('page_heading','users'));'..现在我正在尝试你的建议..和你还有一件事'我的'$ page_headings'是在布局文件中,而不是在行动的视图文件..是否有任何影响..? – Pankaj

+0

@ndm对不起,我说'title_for_layout'错了。它也没有正确显示..尝试你的建议代码后,它显示用户和page_heading都是未定义的,也没有显示页面标题。 – Pankaj

回答

0

发生这种情况是因为我直接从filezilla的编辑选项编辑我的实时服务器文件,并且当我在编辑文件后保存它时,它以某种方式成为单行代码并且因为注释标记了我编辑过的所有代码成了评论。

我纠正了这个问题,当我从服务器采取新鲜的副本。

所以我今天了解到:说经过对文件的工作大约一个半小时,采取从服务器更新的文件,如果你从FileZilla的编辑,因为你不知道它如何会保存文件。

谢谢ndm为您的帮助。