How can i pull data from different tables(models) into view in yii. actually i done this with loadModel method. but my question is how can we import the rules into the view too. Here comes my scenario
I have a User model and Profile model. The User model contains username and password and Profile model contains userid,name,address etc. so in my profile edit view i need all these data with the rules, username-unique,password,confirm pasword-required, etc., i can implement the required rule to all these, but i dunno how to import the table related rules like unique.
How can i pull data from different tables(models) into view in yii . actually
Share
So basically this is a form that takes in two models and displays that data for you to edit and submit.
Simply make the render call to your view and pass both the models. e.g.
$this->render('aview', array('model1'=>$model1, 'model2'=>$model2));Get your view to display the form elements based upon these models.
When you submit simply create new objects for respective models and populate them with the data received. e.g.
Once you have the models populated you can call
validate()on each of them to figure out if the data is according to your rules. If it is you proceed otherwise you display error. I hope this helps unless I missed something in your question.