Ok, well this is one way I think (I’m not saying it is the only way)…
You’ll need to add a custom getter and setter to your model, as well as an attribute, for the search parameter, like so:
private _createdEmail = null;
public function getCreatedEmail() {
if ($this->_createdEmail === null) {
if ($this->created_by === null) {
return null;
}
else {
$this->_createdEmail = $this->createdUser->email;
}
}
return $this->_createdEmail;
}
public function setCreatedEmail($value) {
$this->_createdEmail = $value;
}
You’ll need to add a rule to your rules array to make this parameter safe for massive assignment, like so:
array('createdEmail', 'safe'),
Now you add this to your search function, like so:
if ($this->_createdEmail !== null) {
$criteria->compare('createdUser.email',$this->_createdEmail);
}
And hopefully, all that remains is to use the pseudo attribute in your GridView columns array:
'createdEmail',
You might also want to add it to your attributeLabels array if you want a pretty column title automatically:
'createdEmail' => 'Created By',
To summarize, what you are doing is adding a pseudo attribute to your UserProfile model, which will be the email address of the user who created it (or null if created_by is not set). This means that you can use it everywhere like you would a normal attribute. By adding a safe rule to it, you allow it to be massively assigned from GET/POST forms, which means that the search model can process it. The search function then adds it as a search criteria if it is populated (it might skew search results if not populated), and voila!
I hope this does it for you.