Skip to content

Instantly share code, notes, and snippets.

@kenvunz
Created October 17, 2010 22:18
Show Gist options
  • Save kenvunz/631372 to your computer and use it in GitHub Desktop.
Save kenvunz/631372 to your computer and use it in GitHub Desktop.
Controller and model
<?php
class Abc_Region extends Db_ActiveRecord
{
public $table_name = 'abc_regions';
public $has_many = array(
'countries'=>array('class_name'=>'Shop_Country', 'foreign_key'=>'abc_region_id')
);
public function define_columns($context = null)
{
$this->define_column('id', '#')->invisible();
$this->define_column('name', 'Name')->validation()->fn('trim')->required();
$this->define_multi_relation_column('countries', 'countries', 'Countries', '@name')->validation()->required();
}
public function define_form_fields($context = null)
{
$this->add_form_field('name');
$this->add_form_field('countries');
}
public static function create()
{
return new self();
}
}
?>
<?php
class Abc_Regions extends Backend_Controller
{
public $uri = '/abc/regions';
public $implement = 'Db_ListBehavior, Db_FormBehavior';
public $model = 'Abc_Region';
/*=== Db_ListBehavior ===*/
public $list_model_class = null;
public $list_search_enabled = true;
public $list_search_fields = array('@name');
public $list_search_prompt = 'find region';
public $list_record_url = null;
public $list_custom_body_cells = null;
public $list_custom_head_cells = null;
public $list_top_partial = null;
/*=== Db_FormBehavior ===*/
public $form_model_class = null;
public $form_redirect = null;
public $form_create_title = 'New Region';
public $form_edit_title = 'Edit Region';
public $form_not_found_message = 'Region not found';
public function __construct()
{
parent::__construct();
$this->app_module_name = 'Abc';
$this->app_tab = 'abc';
$this->app_page = 'regions';
$this->form_redirect = $this->url();
$this->list_record_url = $this->url("/edit/");
$this->list_model_class = $this->form_model_class = $this->model;
}
public function index() {
$this->app_page_title = 'Regions';
}
protected function url($slug = "")
{
return url($this->uri . $slug);
}
protected function evalTotal()
{
return Abc_Region::create()->requestRowCount();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment