コード例 #1
0
 public function restIndexBlog()
 {
     $query = $this->getRequest()->getQuery();
     $form = new Form\PostSearchForm();
     $form->bind($query);
     if ($form->isValid()) {
         $query = $form->getData();
     } else {
         return array('form' => $form, 'items' => array());
     }
     $itemModel = Api::_()->getModel('Blog\\Model\\Post');
     $items = $itemModel->setItemList($query)->getPostList();
     $paginator = $itemModel->getPaginator();
     return array('form' => $form, 'items' => $items, 'query' => $query, 'paginator' => $paginator);
 }
コード例 #2
0
 public function indexAction()
 {
     $this->changeViewModel('json');
     $query = $this->getRequest()->getQuery();
     $form = new Form\PostSearchForm();
     $form->bind($query);
     if ($form->isValid()) {
         $query = $form->getData();
     } else {
         return new JsonModel(array('form' => $form, 'items' => array()));
     }
     $itemModel = Api::_()->getModel('Blog\\Model\\Post');
     $items = $itemModel->setItemList($query)->getPostList(array('join' => array('Text' => array('self' => array('*', 'getPreview()')))));
     $paginator = $itemModel->getPaginator();
     $paginator = $paginator ? $paginator->toArray() : null;
     if (Api::_()->isModuleLoaded('User')) {
         $userList = array();
         $userList = $itemModel->getUserList(array('columns' => array('id', 'userName', 'email')))->toArray(array('self' => array('getEmailHash()')));
         $items = $itemModel->combineList($items, $userList, 'User', array('user_id' => 'id'));
     }
     return new JsonModel(array('items' => $items, 'paginator' => $paginator));
 }