public function __construct() { parent::__construct(); if ($this->isPostBack()) { // This is how to add more validations classes // $this->addInputValidation(lang('Company name'), 'name', array(new ValidateInputNotNullOrEmpty(), new ValidateInputMaxLength(50))); $this->addInputValidation(lang('Company name'), 'name', new ValidateInputNotNullOrEmpty()); // If theres no errors, proceed if (!$this->hasErrors()) { // $this->file contains all values for postback files // $this->data contains all values for postback input // We build our own array from the postback data $company = new ModelCompany(); $company->name = $this->data->name; $meta = array(); foreach ($this->data->metakey as $i => $key) { $model = new ModelCompanyData(); $model->key = $key; $model->value = $this->data->metavalue[$i]; $meta[] = $model; } $company->getMetaData()->setRows($meta); $company->save(); $this->setMessage('Company successfully created', 'success'); // Redirect to list view redirect(url('company', 'index')); } } }
public function __construct($id) { parent::__construct(); $this->company = ModelCompany::GetById($id); if (!$this->company->hasRow()) { $this->setMessage(lang('The company does not exist'), 'warning'); // Go back to the list view redirect(url('company', 'index')); } if ($this->isPostBack()) { $this->addInputValidation(lang('Company name'), 'name', new ValidateInputNotNullOrEmpty()); $this->company->name = $this->data->name; $meta = array(); foreach ($this->data->metakey as $i => $key) { $model = new ModelCompanyData(); $model->key = $key; $model->value = $this->data->metavalue[$i]; $meta[] = $model; } $this->company->getMetaData()->setRows($meta); $this->company->update(); $this->setMessage('Company successfully updated', 'success'); // Redirect to list view redirect(url('company', 'index')); } }
public function __construct($id) { parent::__construct(); $company = ModelCompany::GetById($id); if ($company->hasRow()) { $this->setMessage('Company ' . $company->name . ' has been deleted', 'success'); $company->delete(); } else { $this->setMessage('Failed to delete company', 'error'); } redirect(url('company', 'index')); }
public function __construct() { parent::__construct(); $this->companies = ModelCompany::Get($this->getParam('rows', 30), $this->getParam('page', 0)); }