ProfilesController.php 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\controllers;
  3. use app\models\Profile;
  4. class ProfilesController extends \lithium\action\Controller {
  5. public function index() {
  6. $profiles = Profile::all();
  7. return compact('profiles');
  8. }
  9. public function view() {
  10. $profile = Profile::first($this->request->id);
  11. return compact('profile');
  12. }
  13. public function add() {
  14. $profile = Profile::create();
  15. if (($this->request->data) && $profile->save($this->request->data)) {
  16. $this->redirect(array('Profiles::view', 'args' => array($profile->id)));
  17. }
  18. return compact('profile');
  19. }
  20. public function edit() {
  21. $profile = Profile::find($this->request->id);
  22. if (!$profile) {
  23. $this->redirect('Profiles::index');
  24. }
  25. if (($this->request->data) && $profile->save($this->request->data)) {
  26. $this->redirect(array('Profiles::view', 'args' => array($profile->id)));
  27. }
  28. return compact('profile');
  29. }
  30. }
  31. ?>