Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //createAction in userController
- public function createAction()
- {
- $this->view->pageTitle = 'Create User';
- require_once APPLICATION_PATH . '/models/Users.php';
- $userForm = new Form_User();
- if ($this->_request->isPost()) {
- if ($userForm->isValid($_POST)) {
- $userModel = new Model_User();
- $user = $userModel->createUser(
- $userForm->getValue('email'),
- $userForm->getValue('password'),
- $userForm->getValue('url'),
- $userForm->getValue('responsable'),
- $userForm->getValue('role')
- );
- $paises = $this->getRequest()->getParam('pais');
- $userId = intval($user['id']);
- require_once APPLICATION_PATH . '/models/UserHasPais.php';
- $paisesModel = new Model_UsersHasPais($userId);
- $paisesModel->updateUserPais($paises); // This seems to be the problem
- return $this->_forward('list');
- }
- }
- $userForm->setAction('/user/create');
- $this->view->form = $userForm;
- }
- //users model (I promise I'll never have models as tables again, but right now I just want to get this done with)
- class Model_User extends Zend_Db_Table_Abstract {
- /**
- * The default table name
- */
- protected $_name = 'users';
- public function createUser($email, $password, $url, $responsable, $role)
- {
- // create a new row
- $rowUser = $this->createRow();
- if($rowUser) {
- // update the row values
- $rowUser->email = $email;
- $rowUser->password = md5($password);
- $rowUser->url = $url;
- $rowUser->responsable = $responsable;
- $rowUser->role = $role;
- $rowUser->save();
- //return the new user
- return $rowUser;
- } else {
- throw new Zend_Exception("El usuario no se ha podido crear!");
- }
- }
- }
- //users_has_pais model
- class Model_UsersHasPais extends Zend_Db_Table_Abstract
- {
- protected $_name = 'users_has_pais';
- public function __construct($userId)
- {
- $this->userId = $userId;
- }
- public function updateUserPais(array $paises)
- {
- $rowPais = $this->createRow();
- if($rowPais) {
- foreach($rowPais as $pais) {
- $rowPais->users_id = $this->userId;
- $rowPais->pais_id = $pais;
- $rowPais->save();
- }
- }
- }
- }
- /** The ERROR message
- Fatal error: Call to a member function describeTable() on a non-object in /home/fiodorovich/library/ZendFramework/library/Zend/Db/Table/Abstract.php on line 834
- **/
Add Comment
Please, Sign In to add comment