Hum . . . hum. . . . After fiddling around with no success I decided to ask what is the best way to do the following:
I have Person model , which has an id (PK auto increment) , passport number , first name, etc. . .
Now, I have a create form with 2 use cases:
A new member is filling the info and sending - works.
An already registered member is filling only the passport number , pressing a button or link , and is being redirected to the update form with all his info.
Obviously I need somewhere to find a Person model which matches the passport number , get it’s id and call the action update. Easy in words but I’m not sure:
I couldn’t pass the passport number using cHtml link or button (I don’t want to submit the whole form , only the paassport number field)
where should I write the transition between the number and the id? Should I create a new action in the controller? or can I do it in the form itself?
<?php
// protected/models/FindPersonForm.php
class FindPersonForm extends CFormModel {
public $passport;
public function rules() { return array(array("passport","required")); };
public function personExists(){
return Person::model()->findByAttributes(array("passport"=>$this->passport));
}
}
Hello Bluyell, I’v created the model, controller and “some” folder with the view in it (all named as you’v written) , but when I redirect the url to some/findperson I see only white screen.
Probably, that is what usually cause white screen.
I’v fiddled with the code , checked all the brackets , changed CController to Controller , changed the double dashes to single , but I still get the white screen.
Does it matte that there is no filter or access rules for the view in the controller? (I guess no , but still)
Is it enough to add those 3 files manually to yii , or I needed to do anything else?
Oh , double facepalm. . . I hate such moments in code writing:
In the controller render didn’t passed a model create , thus i got the error “unknown model”. I suspected that it can be the problem , but when I copy-pasted it from another controller I took one extra bracket thus it didn’t worked.
Anyway , now it works perfectly!
bluyell - thanks for the great and neat solution! I didn’t knew about the existence of the CformModel before.
georaldc - thanks for the help. Do those 2 lines work in any page? Looks quite handy.