Skip to content

Instantly share code, notes, and snippets.

@crisu83
Created December 8, 2012 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisu83/4237712 to your computer and use it in GitHub Desktop.
Save crisu83/4237712 to your computer and use it in GitHub Desktop.
Dynamic form model for Yii
<?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