Dokumentacja techniczna
Jak używać aplikacji RiseNet CMS
-- -- Struktura tabeli `label` -- CREATE TABLE IF NOT EXISTS `label` ( `id_label` int(10) unsigned NOT NULL AUTO_INCREMENT, `label` varchar(255) NOT NULL, `type` varchar(32) NOT NULL, PRIMARY KEY (`id_label`) ) ENGINE=InnoDB; -- -- Struktura tabeli `label_translation` -- CREATE TABLE IF NOT EXISTS `label_translation` ( `id_label` int(10) unsigned NOT NULL, `id_language` tinyint(3) unsigned NOT NULL, `value` text NOT NULL, PRIMARY KEY (`id_label`,`id_language`), KEY `id_language` (`id_language`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Ograniczenia dla tabeli `label_translation` -- ALTER TABLE `label_translation` ADD CONSTRAINT `label_translation_ibfk_1` FOREIGN KEY (`id_label`) REFERENCES `label` (`id_label`) ON DELETE CASCADE, ADD CONSTRAINT `label_translation_ibfk_2` FOREIGN KEY (`id_language`) REFERENCES `language` (`id_language`) ON DELETE CASCADE;
Label: connection: baza tableName: label columns: id_label: type: integer primary: true autoincrement: true label: type: string (255) notnull: true type: type: string (32) notnull: true default: 'label' LabelTranslation: connection: baza tableName: label_translation attributes: coll_key: id_language columns: id_label: type: integer primary: true id_language: type: integer primary: true value: type: string notnull: true relations: Label: local: id_label foreign: id_label foreignAlias: Translations type: one foreignType: many onDelete: CASCADE Language: local: id_language foreign: id_language foreignAlias: LabelTranslations type: one foreignType: many onDelete: CASCADE
class Admin_LabelController extends Base_Controller_Action_Cms { /** * @var Label */ private $_label; /** * @var Admin_Form_Label */ private $_formLabel; ... public function newAction() { $this->_label = new Label(); $this->_label->type = Label::TYPE_LABEL; $this->_form($this->_label, 'Admin_Form_Label'); } public function editAction() { $this->_label = Label::find($this->getParam('id_label')); $this->forward404Unless($this->_label); $this->_form($this->_label, 'Admin_Form_Label'); } ...
class Admin_Form_Label extends Twitter_Bootstrap_Form_Horizontal { protected $_belong_to = 'Admin_Form_Label'; /** * @var Label */ protected $_model; public function init() { $fields = array(); $fields['name'] = $this->createElement( 'text', 'label', array( 'label' => 'label', 'required' => true, 'allowEmpty' => false, 'filters' => array('StringTrim'), 'validators' => array( array('NotEmpty', true), array('StringLength', true, array('max' => 255)) ), 'value' => $this->_model->getLabel(), )); $labelTypeOptions = Label::getTypes(); $fields['type'] = $this->createElement( 'select', 'type', array( 'label' => 'type', 'required' => true, 'multiOptions' => $labelTypeOptions, 'allowEmpty' => false, 'validators' => array( array('NotEmpty', true), array('InArray', true, array(array_keys($labelTypeOptions))) ), 'value' => $this->_model->getType(), )); $fields['value'] = $this->createElement('text', 'value', array( 'label' => 'value', 'filters' => array('StringTrim'), 'validators' => array( array('StringLength', true, array('max' => 255)) ), 'value' => $this->_model->getValue() )); $fields['submit'] = $this->createElement('submit', 'submit', array( 'label' => 'submit', )); $this->addDisplayGroup($fields, 'main', array( 'legend' => 'label information', )); } }
Aplikacja po każdej poprawnej walidacji uzupełnia pola rekordu których nazwa występuje w formularzu. Dotyczy to także obsługi wersji językowych, wartość np: nazwy, zostanie zapisana w aktualnie wybranej wersji językowej.
Po każdej poprawnej walidacji aplikacja uzupełnia pola rekordu z danych formularza poprzez metodę set{'nazwa_pola'}($value, [$id_language = null])
, np: setTitle($value)
. W przypadku potrzeby własnej obsługi uzupełnienia danych wystarczy w danym modelu nadpisać potrzebną nam metodę. Dla przykładu zapis hasła użytkowika:
class User extends Table_User { ... /** * @param $value * @return $this */ public function setPassword($value) { if(strlen($value) > 0 ){ $this->password = Base_Auth::hashPassword($value); } return $this; } ... }
Po każdej poprawnej walidacji formularza wykonywana jest metoda postIsVaild()
na formularzu. Domyślnie metoda uzupełnia rekord o dane pochodzące z formularza a wynikiem operacji jest wartość true
.
W celu indywidualnej obsługi formualrza np: dodatkowej walidacji lub uzupełnienia rekordu wystarczy w samym formularzu stworzyć metodę postIsValid()
, przykład:
class Page_Form_Admin_Page extends Twitter_Bootstrap_Form_Horizontal { ... protected function postIsValid($data) { $layout = explode('-', $this->getValue('layout')); $this->_model->setDataMapLayout($layout[0]); $this->_model->setDataMapModule($layout[1])); return parent::postIsValid($data); } }