class User extends DataMapper { var $has_one = array('group','contact','user'); var $validation = array ( 'username' => array ( 'label' => 'Username', 'rules' => array('trim', 'required', 'unique', 'min_length' => 4, 'max_lenght' => 50) ) ); function __construct($id = NULL) { parent::__construct($id); } function __toString() { return $this->username; } } class Contact extends Datamapper { var $has_one = array('user'); var $validation = array ( 'name' => array ( 'label' => 'Full name', 'rules' => array('trim','required', 'min_length' => 5, 'max_length' => 255) ) ); function __construct($id = NULL) { parent::__construct($id); } function __toString() { return $this->name; } } class Group extends Datamapper { var $has_many = array('user'); var $validation = array ( 'name' => array ( 'label' => 'Name', 'type' => 'dropdown', 'rules' => array('required') ) ); function __construct($id = NULL) { parent::__construct($id); } function __toString() { return $this->name; } }
echo $user->render_form ( array ( 'username', 'group' => array ( 'label' => 'Group', 'type' => 'dropdown' ), 'contact_name' => array ( 'label' => 'Full name', 'type' => 'text' ) ), "admin/users/edit/{$user->id}", array ( 'save_button' => 'Change' ) );
function edit($id = NULL) { $user = new User(); $user->where('id',$id); $user->include_related('contact',array('name')); $user->get(); if($this->input->post('username')) { $related = $user->from_array($_POST, array('username','group','contact_name')); $user->save($related); } $data['main_content'] = 'admin/users/edit_view.php'; $data['user'] = $user; $this->load->view('admin/template.php', $data); }