Guest User

Untitled

a guest
Nov 4th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. use PhalconMvcModelCriteria;
  2. use PhalconPaginatorAdapterModel as Paginator;
  3. use Phalcon_PunchUsers;
  4. /**
  5. * Creates a new user
  6. */
  7. public function createAction()
  8. {
  9. if (!$this->request->isPost()) {
  10. $this->dispatcher->forward([
  11. 'controller' => "users",
  12. 'action' => 'index'
  13. ]);
  14.  
  15. return;
  16. }
  17.  
  18. $user = new Users();
  19. $user->setlastName($this->request->getPost("LastName"));
  20. $user->setfirstName($this->request->getPost("FirstName"));
  21. $user->setlogin($this->request->getPost("Login"));
  22. $user->setpassword($this->request->getPost("Password"));
  23. $user->seteMail($this->request->getPost("eMail"));
  24. var_dump($this->request->getPost("LastName"));
  25. var_dump($this->request->getPost("FirstName"));
  26. var_dump($this->request->getPost("Login"));
  27. var_dump($this->request->getPost("Password"));
  28. var_dump($this->request->getPost("eMail"));
  29.  
  30.  
  31. if (!$user->save()) {
  32. foreach ($user->getMessages() as $message) {
  33. $this->flash->error($message);
  34. }
  35.  
  36. $this->dispatcher->forward([
  37. 'controller' => "users",
  38. 'action' => 'new'
  39. ]);
  40.  
  41. return;
  42. }
  43.  
  44. $this->flash->success("user was created successfully");
  45.  
  46. $this->dispatcher->forward([
  47. 'controller' => "users",
  48. 'action' => 'index'
  49. ]);
  50. }
  51.  
  52. <?php echo $this->getContent(); ?>
  53.  
  54. <?php
  55. echo $this->tag->form(
  56. [
  57. "users/create",
  58. "class" => "form-horizontal"
  59. ]
  60. );
  61. ?>
  62.  
  63. <div class="form-group">
  64. <label for="fieldLastname" class="col-sm-2 control-label">LastName</label>
  65. <div class="col-sm-10">
  66. <?php echo $this->tag->textField(["LastName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldLastname"]) ?>
  67. </div>
  68. </div>
  69.  
  70. <div class="form-group">
  71. <label for="fieldFirstname" class="col-sm-2 control-label">FirstName</label>
  72. <div class="col-sm-10">
  73. <?php echo $this->tag->textField(["FirstName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldFirstname"]) ?>
  74. </div>
  75. </div>
  76.  
  77. <div class="form-group">
  78. <label for="fieldLogin" class="col-sm-2 control-label">Login</label>
  79. <div class="col-sm-10">
  80. <?php echo $this->tag->textField(["Login", "size" => 30, "class" => "form-control", "id" => "fieldLogin"]) ?>
  81. </div>
  82. </div>
  83.  
  84. <div class="form-group">
  85. <label for="fieldPassword" class="col-sm-2 control-label">Password</label>
  86. <div class="col-sm-10">
  87. <?php echo $this->tag->passwordField(["Password", "size" => 30, "class" => "form-control", "id" => "fieldPassword"]) ?>
  88. </div>
  89. </div>
  90.  
  91. <div class="form-group">
  92. <label for="fieldEmail" class="col-sm-2 control-label">EMail</label>
  93. <div class="col-sm-10">
  94. <?php echo $this->tag->textField(["eMail", "size" => 30, "class" => "form-control", "id" => "fieldEmail"]) ?>
  95. </div>
  96. </div>
  97.  
  98.  
  99. <div class="form-group">
  100. <div class="col-sm-offset-2 col-sm-10">
  101. <?php echo $this->tag->submitButton(["Save", "class" => "btn btn-default"]) ?>
  102. </div>
  103. </div>
  104.  
  105. <?php echo $this->tag->endForm();?>
  106.  
  107. <?php
  108. use PhalconValidation;
  109. use PhalconValidationValidatorUniqueness as UniquenessValidator;
  110.  
  111. namespace Phalcon_Punch;
  112.  
  113. class Users extends PhalconMvcModel
  114. {
  115.  
  116. /**
  117. *
  118. * @var integer
  119. */
  120. protected $iD;
  121.  
  122. /**
  123. *
  124. * @var string
  125. */
  126. protected $lastName;
  127.  
  128. /**
  129. *
  130. * @var string
  131. */
  132. protected $firstName;
  133.  
  134. /**
  135. *
  136. * @var string
  137. */
  138. protected $login;
  139.  
  140. /**
  141. *
  142. * @var string
  143. */
  144. protected $password;
  145.  
  146. /**
  147. *
  148. * @var string
  149. */
  150. protected $grants;
  151.  
  152. /**
  153. *
  154. * @var string
  155. */
  156. protected $status;
  157.  
  158. /**
  159. *
  160. * @var string
  161. */
  162. protected $lastUpdateDate;
  163.  
  164. /**
  165. *
  166. * @var string
  167. */
  168. protected $eMail;
  169.  
  170. /**
  171. *
  172. * @var string
  173. */
  174. protected $tag;
  175.  
  176. /**
  177. * Method to set the value of field ID
  178. *
  179. * @param integer $iD
  180. * @return $this
  181. */
  182. public function setID($iD)
  183. {
  184. $this->iD = $iD;
  185.  
  186. return $this;
  187. }
  188.  
  189. /**
  190. * Method to set the value of field LastName
  191. *
  192. * @param string $lastName
  193. * @return $this
  194. */
  195. public function setLastName($lastName)
  196. {
  197. $this->lastName = $lastName;
  198.  
  199. return $this;
  200. }
  201.  
  202. /**
  203. * Method to set the value of field FirstName
  204. *
  205. * @param string $firstName
  206. * @return $this
  207. */
  208. public function setFirstName($firstName)
  209. {
  210. $this->firstName = $firstName;
  211.  
  212. return $this;
  213. }
  214.  
  215. /**
  216. * Method to set the value of field Login
  217. *
  218. * @param string $login
  219. * @return $this
  220. */
  221. public function setLogin($login)
  222. {
  223. $this->login = $login;
  224.  
  225. return $this;
  226. }
  227.  
  228. /**
  229. * Method to set the value of field Password
  230. *
  231. * @param string $password
  232. * @return $this
  233. */
  234. public function setPassword($password)
  235. {
  236. $this->password = $password;
  237.  
  238. return $this;
  239. }
  240.  
  241. /**
  242. * Method to set the value of field Grants
  243. *
  244. * @param string $grants
  245. * @return $this
  246. */
  247. public function setGrants($grants)
  248. {
  249. $this->grants = $grants;
  250.  
  251. return $this;
  252. }
  253.  
  254. /**
  255. * Method to set the value of field Status
  256. *
  257. * @param string $status
  258. * @return $this
  259. */
  260. public function setStatus($status)
  261. {
  262. $this->status = $status;
  263.  
  264. return $this;
  265. }
  266.  
  267. /**
  268. * Method to set the value of field LastUpdateDate
  269. *
  270. * @param string $lastUpdateDate
  271. * @return $this
  272. */
  273. public function setLastUpdateDate($lastUpdateDate)
  274. {
  275. $this->lastUpdateDate = $lastUpdateDate;
  276.  
  277. return $this;
  278. }
  279.  
  280. /**
  281. * Method to set the value of field eMail
  282. *
  283. * @param string $eMail
  284. * @return $this
  285. */
  286. public function setEMail($eMail)
  287. {
  288. $this->eMail = $eMail;
  289.  
  290. return $this;
  291. }
  292.  
  293. /**
  294. * Method to set the value of field tag
  295. *
  296. * @param string $tag
  297. * @return $this
  298. */
  299. public function setTag($tag)
  300. {
  301. $this->tag = $tag;
  302.  
  303. return $this;
  304. }
  305.  
  306. /**
  307. * Returns the value of field iD
  308. *
  309. * @return integer
  310. */
  311. public function getID()
  312. {
  313. return $this->iD;
  314. }
  315.  
  316. /**
  317. * Returns the value of field lastName
  318. *
  319. * @return string
  320. */
  321. public function getLastName()
  322. {
  323. return $this->lastName;
  324. }
  325.  
  326. /**
  327. * Returns the value of field firstName
  328. *
  329. * @return string
  330. */
  331. public function getFirstName()
  332. {
  333. return $this->firstName;
  334. }
  335.  
  336. /**
  337. * Returns the value of field login
  338. *
  339. * @return string
  340. */
  341. public function getLogin()
  342. {
  343. return $this->login;
  344. }
  345.  
  346. /**
  347. * Returns the value of field password
  348. *
  349. * @return string
  350. */
  351. public function getPassword()
  352. {
  353. return $this->password;
  354. }
  355.  
  356. /**
  357. * Returns the value of field grants
  358. *
  359. * @return string
  360. */
  361. public function getGrants()
  362. {
  363. return $this->grants;
  364. }
  365.  
  366. /**
  367. * Returns the value of field status
  368. *
  369. * @return string
  370. */
  371. public function getStatus()
  372. {
  373. return $this->status;
  374. }
  375.  
  376. /**
  377. * Returns the value of field lastUpdateDate
  378. *
  379. * @return string
  380. */
  381. public function getLastUpdateDate()
  382. {
  383. return $this->lastUpdateDate;
  384. }
  385.  
  386. /**
  387. * Returns the value of field eMail
  388. *
  389. * @return string
  390. */
  391. public function getEMail()
  392. {
  393. return $this->eMail;
  394. }
  395.  
  396. /**
  397. * Returns the value of field tag
  398. *
  399. * @return string
  400. */
  401. public function getTag()
  402. {
  403. return $this->tag;
  404. }
  405.  
  406. /**
  407. * Initialize method for model.
  408. */
  409. public function initialize()
  410. {
  411. $this->setSchema("basephalcon");
  412. $this->setSource("users");
  413. }
  414.  
  415. /**
  416. * Returns table name mapped in the model.
  417. *
  418. * @return string
  419. */
  420. public function getSource()
  421. {
  422. return 'users';
  423. }
  424.  
  425. /**
  426. * Allows to query a set of records that match the specified conditions
  427. *
  428. * @param mixed $parameters
  429. * @return Users[]|Users|PhalconMvcModelResultSetInterface
  430. */
  431. public static function find($parameters = null)
  432. {
  433. return parent::find($parameters);
  434. }
  435.  
  436. /**
  437. * Allows to query the first record that match the specified conditions
  438. *
  439. * @param mixed $parameters
  440. * @return Users|PhalconMvcModelResultInterface
  441. */
  442. public static function findFirst($parameters = null)
  443. {
  444. return parent::findFirst($parameters);
  445. }
  446.  
  447. public function validation()
  448. {
  449. $validator= new Validation();
  450. $uValidator = new UniquenessValidator(["message" => "this Login has already been chosen"]);
  451. $validator->add('login', $uValidator);
  452. return $this->validate($validator);
  453. }
  454.  
  455. }
Add Comment
Please, Sign In to add comment