Hi,
Today we have the following code:
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
(...)
}
I suggest add the getPosted() function to CModel, so you can turn the previous code into this:
$model=new ContactForm;
if($model->posted)
{
$model->attributes=$model->posted;
(...)
}
Advantages:
-
More code reusing
-
We can change the class name and the controllers still work without any other change
I’ve been using this in my projects, and it is a tiny feature that actually helps. Here it is my implementation:
public function getPosted() {
$name = get_called_class();
if (isset($_POST[$name])) {
return $_POST[$name];
} else {
return false;
}
}