Guest User

Untitled

a guest
Dec 3rd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. //createAction in userController
  2. public function createAction()
  3. {
  4. $this->view->pageTitle = 'Create User';
  5. require_once APPLICATION_PATH . '/models/Users.php';
  6. $userForm = new Form_User();
  7. if ($this->_request->isPost()) {
  8. if ($userForm->isValid($_POST)) {
  9. $userModel = new Model_User();
  10. $user = $userModel->createUser(
  11. $userForm->getValue('email'),
  12. $userForm->getValue('password'),
  13. $userForm->getValue('url'),
  14. $userForm->getValue('responsable'),
  15. $userForm->getValue('role')
  16. );
  17. $paises = $this->getRequest()->getParam('pais');
  18. $userId = intval($user['id']);
  19.  
  20. require_once APPLICATION_PATH . '/models/UserHasPais.php';
  21. $paisesModel = new Model_UsersHasPais($userId);
  22. $paisesModel->updateUserPais($paises); // This seems to be the problem
  23.  
  24. return $this->_forward('list');
  25. }
  26. }
  27. $userForm->setAction('/user/create');
  28. $this->view->form = $userForm;
  29. }
  30.  
  31. //users model (I promise I'll never have models as tables again, but right now I just want to get this done with)
  32.  
  33. class Model_User extends Zend_Db_Table_Abstract {
  34. /**
  35. * The default table name
  36. */
  37. protected $_name = 'users';
  38.  
  39. public function createUser($email, $password, $url, $responsable, $role)
  40. {
  41. // create a new row
  42. $rowUser = $this->createRow();
  43. if($rowUser) {
  44. // update the row values
  45. $rowUser->email = $email;
  46. $rowUser->password = md5($password);
  47. $rowUser->url = $url;
  48. $rowUser->responsable = $responsable;
  49. $rowUser->role = $role;
  50. $rowUser->save();
  51. //return the new user
  52. return $rowUser;
  53. } else {
  54. throw new Zend_Exception("El usuario no se ha podido crear!");
  55. }
  56. }
  57. }
  58.  
  59. //users_has_pais model
  60.  
  61. class Model_UsersHasPais extends Zend_Db_Table_Abstract
  62. {
  63. protected $_name = 'users_has_pais';
  64.  
  65. public function __construct($userId)
  66. {
  67. $this->userId = $userId;
  68. }
  69.  
  70. public function updateUserPais(array $paises)
  71. {
  72. $rowPais = $this->createRow();
  73. if($rowPais) {
  74. foreach($rowPais as $pais) {
  75. $rowPais->users_id = $this->userId;
  76. $rowPais->pais_id = $pais;
  77. $rowPais->save();
  78. }
  79. }
  80. }
  81. }
  82. /** The ERROR message
  83. 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
  84. **/
Add Comment
Please, Sign In to add comment