我只是想表明一種形式using form builder顯示一個無辜的形式,但字段不顯示。這是代碼:警予:剛嘗試使用表單生成
register.php
entered here
<div class="form">
<?php echo $form?>
</div>
RegisterForm.php
class RegisterForm extends CFormModel {
public $name;
}
MyController.php
public function actionRegister()
{
$model = new RegisterForm();
$config=array(
'elements'=>array(
'name'=>array(
'type'=>'text',
),
),
);
$form = new CForm($config, $model);
$this->render('register', array('form' => $form));
}
EDIT 1:
我是缺少在RegisterForm.php規則..
public function rules()
{
return array(
array('name', 'required'),
);
}
所以,規則是強制性??? 反正林興趣也顯示separatedly領域,所以我想這:
<div class="form">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::activeTextField($form,'name') ?>
<?php echo CHtml::endForm(); ?>
</div>
,但我得到這個錯誤:
CForm and its behaviors do not have a method or closure named "getValidators".
/home/javiergarcia/programacion/libs/yii/framework/base/CComponent.php(266)
254 public function __call($name,$parameters)
255 {
256 if($this->_m!==null)
257 {
258 foreach($this->_m as $object)
259 {
260 if($object->getEnabled() && method_exists($object,$name))
261 return call_user_func_array(array($object,$name),$parameters);
262 }
263 }
264 if(class_exists('Closure', false) && $this->canGetProperty($name) && $this->$name instanceof Closure)
265 return call_user_func_array($this->$name, $parameters);
266 throw new CException(Yii::t('yii','{class} and its behaviors do not have a method or closure named "{name}".',
267 array('{class}'=>get_class($this), '{name}'=>$name)));
268 }
編輯2:
的評論後dInGd0nG:
object(CForm)#35 (17) {
["title"]=>
NULL
["description"]=>
NULL
["method"]=>
string(4) "post"
["action"]=>
string(0) ""
["inputElementClass"]=>
string(17) "CFormInputElement"
["buttonElementClass"]=>
string(18) "CFormButtonElement"
["attributes"]=>
array(0) {
}
["showErrorSummary"]=>
bool(false)
["activeForm"]=>
array(1) {
["class"]=>
string(11) "CActiveForm"
}
["_model":"CForm":private]=>
object(my-firm\web\models\forms\RegisterOrganizationForm)#34 (9) {
["organization_name"]=>
NULL
["email"]=>
NULL
["password"]=>
NULL
["repeatPassword"]=>
NULL
["_errors":"CModel":private]=>
array(0) {
}
["_validators":"CModel":private]=>
NULL
["_scenario":"CModel":private]=>
string(0) ""
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
["_elements":"CForm":private]=>
object(CFormElementCollection)#36 (6) {
["_form":"CFormElementCollection":private]=>
*RECURSION*
["_forButtons":"CFormElementCollection":private]=>
bool(false)
["_d":"CMap":private]=>
array(1) {
["organization_name"]=>
object(CFormInputElement)#37 (15) {
["type"]=>
string(4) "text"
["name"]=>
string(17) "organization_name"
["hint"]=>
NULL
["items"]=>
array(0) {
}
["errorOptions"]=>
array(0) {
}
["enableAjaxValidation"]=>
bool(true)
["enableClientValidation"]=>
bool(true)
["layout"]=>
string(30) "{label}
{input}
{hint}
{error}"
["_label":"CFormInputElement":private]=>
NULL
["_required":"CFormInputElement":private]=>
NULL
["attributes"]=>
array(0) {
}
["_parent":"CFormElement":private]=>
*RECURSION*
["_visible":"CFormElement":private]=>
NULL
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
}
["_r":"CMap":private]=>
bool(false)
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
["_buttons":"CForm":private]=>
NULL
["_activeForm":"CForm":private]=>
NULL
["_parent":"CFormElement":private]=>
object(SiteController)#24 (19) {
["layout"]=>
string(14) "//layouts/main"
["menu"]=>
array(0) {
}
["breadcrumbs"]=>
array(0) {
}
["baseUrl"]=>
string(15) "//my-firm.local"
["assetsUrl"]=>
string(16) "/assets/e876fe71"
["bodyClass"]=>
string(9) "sidebar-3"
["_viewVars":"my-firm\core\Controller":private]=>
array(2) {
["model"]=>
object(my-firm\web\models\forms\LoginForm)#31 (9) {
["email"]=>
NULL
["pass"]=>
NULL
["rememberMe"]=>
NULL
["_identity":"my-firm\web\models\forms\LoginForm":private]=>
NULL
["_errors":"CModel":private]=>
array(0) {
}
["_validators":"CModel":private]=>
NULL
["_scenario":"CModel":private]=>
string(0) ""
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
["linkSchools"]=>
string(39) "https://my-firm.local/escoles/espana/76"
}
["defaultAction"]=>
string(5) "index"
["_id":"CController":private]=>
string(4) "site"
["_action":"CController":private]=>
object(CInlineAction)#32 (4) {
["_id":"CAction":private]=>
string(20) "RegisterOrganization"
["_controller":"CAction":private]=>
*RECURSION*
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
["_pageTitle":"CController":private]=>
NULL
["_cachingStack":"CController":private]=>
NULL
["_clips":"CController":private]=>
NULL
["_dynamicOutput":"CController":private]=>
NULL
["_pageStates":"CController":private]=>
NULL
["_module":"CController":private]=>
NULL
["_widgetStack":"CBaseController":private]=>
array(0) {
}
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
["_visible":"CFormElement":private]=>
NULL
["_e":"CComponent":private]=>
NULL
["_m":"CComponent":private]=>
NULL
}
Ja VIER
嘗試'的var_dump($形式)'在之前myController的'$這個 - >渲染()'和粘貼O/p這裏 – dInGd0nG
完成---------- – user1077220
我認爲你的錯誤出現在你想分開顯示這些字段的部分,你到底在做什麼在那裏? –