在我的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。我無法讓它工作。可以請任何人幫忙。
在此先感謝。
而且'title_for_layout'也被提交了嗎?它應該沒有什麼區別,但是如何使用一個集合調用'$ this-> set(compact('title_for_layout','page_heading','users'));'? – ndm
你的''title_for_layout'來了不錯..我試着把數組變量放在一起'$ this-> set(compact('page_heading','users'));'..現在我正在嘗試你的建議..和你還有一件事'我的'$ page_headings'是在佈局文件中,而不是在行動的視圖文件..是否有任何影響..? – Pankaj
@ndm對不起,我說'title_for_layout'錯了。它也沒有正確顯示..嘗試你的建議代碼後,它顯示用戶和page_heading都是未定義的,也沒有顯示頁面標題。 – Pankaj