Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = Zend_Db_Table::getDefaultAdapter();
- $entityTable = new Model_{name}();
- $form = new Backend_Form_{name}();
- if ($this->_request->isPost()) {
- if ($form->isValid($this->_request->getPost())) {
- Zend_Db_Table::getDefaultAdapter()->beginTransaction();
- $entity = $entityTable->fetchNew();
- $entity->field1 = $form->getValue('field_name');
- .....
- $entity->save(); // insert
- //
- $entity->save(); // update
- Zend_Db_Table::getDefaultAdapter()->commit();
- } else
- $form->populate($this->_request->getPost());
- } else {
- $form->populate ($entity->toArrayy());
- }
- /**
- * Entity ClassA
- */
- class Model_EntityA extends Application_Db_Table_Abstract {
- protected $_name = 'table_name';
- protected $_primary = 'id';
- protected $_rowClass = 'Application_Db_Table_Row';
- protected $_dependentTables = array(
- 'Model_EntityA',
- 'Model_EntityM'
- );
- }
- /*
- * Class to handle ManyToMany
- */
- class Model_EntityM extends Application_Db_Table_Abstract {
- protected $_name = 'table_name';
- protected $_primary = 'id';
- protected $_rowClass = 'Application_Db_Table_Row';
- protected $_referenceMap = array(
- 'boutique' => array(
- 'columns' => 'a_id',
- 'refTableClass' => 'Model_EntityA',
- 'refColumns' => 'id'
- ),
- 'produit' => array(
- 'columns' => 'b_id',
- 'refTableClass' => 'Model_EntityB',
- 'refColumns' => 'id'
- )
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment