Advertisement
Ordog23

Controller being called via HMVC

Jan 7th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. Dpublic function post_details() {
  2.         if (! \Request::is_hmvc()) {
  3.             \Log::debug('No HMVC');
  4.             $data['id'] = \Input::post('id', FALSE);
  5.         } else {
  6.             \Log::Debug('HMVC');
  7.             $data['id'] = $this->param('id');
  8.         }
  9.         \Log::Debug('DCMS API - Book: ' . $data['id']);
  10.         if ($data['id'] !== FALSE && $data['id'] !== NULL) {
  11.             \Log::debug('Retrieving book details - ID' . $data['id']);
  12.             $books = \Model_Book::query()->where('id', $data['id'])->get();
  13.             $details = array();
  14.             foreach ($books as $book) {
  15.                 $details['title'] = $book->name;
  16.                 $details['author'] = array();
  17.                 foreach ($book->authors as $a) {
  18.                     \Arr::insert($details['author'], $a->name,0);
  19.                 }
  20.             }
  21.             return $details;
  22.         } else {
  23.             \Log::Debug('Post was empty');
  24.             $details['error'] = 'no_id_given';
  25.             return $details;
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement