I am new in Yii. I am developing some task but I have problem. I Create a Form Like this
I have also created CFormModel
class Abc extends CFormModel
public function actionRegister()
$this->render(“reg”,array(‘w’=>$w)); //reg is name of form file
$w->setAttributes($_POST['Abc']); // Model is empty
print_r($w->attributes); //this line creates problem
This set of code create problem and model is empty.Can you solve this sort of task.
Thank you very much
I suspect the attributes are not being filled by the setAttributes call because you have not declared them “safe” in the rules. If this is true, you’ll see something in your logs like “attempt to set unsafe attribute”.
If this is the problem, add this to your model (class Abc):
public function rules()
The safe attribute only affects the bulk population function: setAttributes. You can still set unsafe attributes manually, e.g.
$w->name = "Fred";
You can also override the default behavior of setAttributes to read all attributes, not just the safe ones:
public void setAttributes(array $values, boolean $safeOnly=true)
So this would also fix your problem:
Thank You very much
Can you describe steps how to trigger validation?
I have tested this.
In register action
set of code
validation is not performed and error is not displayed