controller.txt.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. namespace {:namespace};
  2. use {:use};
  3. use lithium\action\DispatchException;
  4. class {:class} extends \lithium\action\Controller {
  5. public function index() {
  6. ${:plural} = {:model}::all();
  7. return compact('{:plural}');
  8. }
  9. public function view() {
  10. ${:singular} = {:model}::first($this->request->id);
  11. return compact('{:singular}');
  12. }
  13. public function add() {
  14. ${:singular} = {:model}::create();
  15. if (($this->request->data) && ${:singular}->save($this->request->data)) {
  16. return $this->redirect(array('{:name}::view', 'args' => array(${:singular}->id)));
  17. }
  18. return compact('{:singular}');
  19. }
  20. public function edit() {
  21. ${:singular} = {:model}::find($this->request->id);
  22. if (!${:singular}) {
  23. return $this->redirect('{:name}::index');
  24. }
  25. if (($this->request->data) && ${:singular}->save($this->request->data)) {
  26. return $this->redirect(array('{:name}::view', 'args' => array(${:singular}->id)));
  27. }
  28. return compact('{:singular}');
  29. }
  30. public function delete() {
  31. if (!$this->request->is('post') && !$this->request->is('delete')) {
  32. $msg = "{:name}::delete can only be called with http:post or http:delete.";
  33. throw new DispatchException($msg);
  34. }
  35. {:model}::find($this->request->id)->delete();
  36. return $this->redirect('{:name}::index');
  37. }
  38. }