2011-05-31 53 views
0

當我創建我的網頁indexSuccess.php的,我用的指示等:如何解決注意:未定義的變量:形式...?

Notice: Undefined variable: form in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84 

    Fatal error: Call to a member function render() on a non-object in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84 

我可以DOAS爲題解:

<?php echo $form['titre']->render();?> 

執行就像當它給了我一個錯誤?

+2

你的形式分配給您的行動模板'$ form':'$這個 - >形式=新WhateverClassForm();'? – prodigitalson 2011-05-31 02:35:43

回答

0

當您自動生成一個學說的模式,形式創建爲局部的,嵌入在新&編輯模板。如果你檢查你的newSuccess,createSuccess,editSuccess,updateSuccess行動,你會發現表單變量的賦值由prodigitalson提到的,因此這個錯誤不會出現在那裏。

但是,窗體不會自動在indexSuccess提供,如命名約定頁面應該用於列明的對象。打破慣例可能會導致稍後的混亂。

還有一個提示:如果你想創建一個類似於symfony admin後臺的屏幕,你可以在其中列出所有的對象以及添加/編輯對象的表單,你可以使用generator.yml自動生成你的視圖。請務必在symfony目錄中包含css,js & web/sf文件夾中的圖像

0

因此,我找到了我正在搜索的內容。我忘了補充

$this->form = new addAnnonceForm(); 

在我executeIndex(動作)

THX :)

相關問題