Created
December 8, 2012 00:11
-
-
Save crisu83/4237712 to your computer and use it in GitHub Desktop.
Dynamic form model for Yii
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DynamicForm extends CFormModel | |
{ | |
private $_rules = array(); | |
private $_properties = array(); | |
public function __set($name, $value) | |
{ | |
if (isset($this->_properties[$name])) | |
$this->_properties[$name] = $value; | |
else | |
parent::__set($name, $value); | |
} | |
public function __get($name) | |
{ | |
if (isset($this->_properties[$name])) | |
return $this->_properties[$name]; | |
else | |
return parent::__get($name); | |
} | |
public function rules() | |
{ | |
return $this->_rules; | |
} | |
public function setPropertyNames(array $names) | |
{ | |
if (empty($this->_properties)) | |
{ | |
foreach ($names as $name) | |
$this->_properties[$name] = ''; | |
} | |
} | |
public function setRules(array $rules) | |
{ | |
$this->_rules = $rules; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment