php - how to get table fields in yii? -
i working on new controller user role.
when called $user = new user(); user table form fields value display
<?php public function actioncreate() { $request = yii::app()->request; $notify = yii::app()->notify; $user = new user(); if ($request->ispostrequest && ($attributes = (array)$request->getpost($user->modelname, array()))) { $user->attributes = $attributes; if (!$user->save()) { $notify->adderror(yii::t('app', 'your form has few errors, please prepare them , seek again!')); } else { $notify->addsuccess(yii::t('app', 'your form has been saved!')); } yii::app()->hooks->doaction('controller_action_save_data', $collection = new cattributecollection(array( 'controller' => $this, 'success' => $notify->hassuccess, 'user' => $user, ))); if ($collection->success) { $this->redirect(array('users/index')); } } $this->setdata(array( 'pagemetatitle' => $this->data->pagemetatitle . ' | '. yii::t('users', 'create new user'), 'pageheading' => yii::t('users', 'create new user'), 'pagebreadcrumbs' => array( yii::t('users', 'users') => $this->createurl('users/index'), yii::t('app', 'create new'), ) )); $this->render('form', compact('user')); } ?>
display form
<?php echo $form->labelex($user , 'first_name');?> <?php echo $form->textfield($user , 'first_name', $role->gethtmloptions('first_name')); ?> <?php echo $form->error($user , 'first_name');?>
but when $role = new role(); user role table getting error
<?php public function actioncreate() { $request = yii::app()->request; $notify = yii::app()->notify; $role = new role(); if ($request->ispostrequest && ($attributes = (array)$request->getpost($role->modelname, array()))) { $role->attributes = $attributes; if (!$role->save()) { $notify->adderror(yii::t('app', 'your form has few errors, please prepare them , seek again!')); } else { $notify->addsuccess(yii::t('app', 'your form has been saved!')); } yii::app()->hooks->doaction('controller_action_save_data', $collection = new cattributecollection(array( 'controller' => $this, 'success' => $notify->hassuccess, 'user' => $user, ))); if ($collection->success) { $this->redirect(array('users_role/index')); } } $this->setdata(array( 'pagemetatitle' => $this->data->pagemetatitle . ' | '. yii::t('roles', 'create new role'), 'pageheading' => yii::t('roles', 'create new role'), 'pagebreadcrumbs' => array( yii::t('roles', 'roles') => $this->createurl('users_role/index'), yii::t('app', 'create new role'), ) )); $this->render('form', compact('role')); } ?>
not display form
<?php echo $form->labelex($role, 'role_name');?> <?php echo $form->textfield($role, 'role_name', $role->gethtmloptions('role_name')); ?> <?php echo $form->error($role, 'role_name');?>
plz help me..
php yii
No comments:
Post a Comment