class Model_Users extends Model_Table{ public $table = 'user'; function init() { parent::init(); $this->addField('display_name')->caption('Display name'); $this->addField('email');//->type('email'); $this->addField('password')->type('password')->mandatory('Enter the password.'); $this->addField('birth_date')->type('date'); $this->addField('created')->type('datetime')->defaultValue(date('Y-m-d H:i:s')); $this->addField('status')->enum(array('active','ban','disable'))->mandatory('Please select user status.')->defaultValue('active'); $this->addField('is_admin')->type('boolean')->caption('Admin'); $this->addField('is_editor')->type('boolean')->caption('Editor'); $this->addField('is_blogger')->type('boolean')->caption('Blogger'); $this->addField('is_member')->type('boolean')->defaultValue(1)->caption('Member'); $this->addHook('beforeSave',function($m){ $m['email'] = trim(strtolower($m['email'])); }); } }
class page_test extends Page { public function init() { parent::init(); //--------- CRUD --------- $crud = $this->add('CRUD'); $crud->setModel('Users'); if ($crud->grid) { $crud->grid->getColumn('display_name')->makeSortable(); $crud->grid->getColumn('email')->makeSortable(); $crud->grid->getColumn('created')->makeSortable(); $crud->grid->addQuickSearch(array('display_name', 'email')); $crud->grid->addPaginator(5); } //--------- Form --------- $this->add('HTML')->set('<h2>Test user form</h2>'); $form = $this->add('Form'); $form->setModel('Users'); $form->addSubmit(); } }
$this->add('CRUD');
$this->hasOne('User', 'user_id', 'display_name');
$this->addField('blog_category_id')->refModel('Blog_Category')->mandatory(true); // อ้างอิงไปยังโมเดล Blog_Category