Example #1
0
 public function generate($slug, $method = 'all', $limit = 20, $page = 1, $sort = [], $fields = [])
 {
     $value = null;
     if ($method == 'byId' || $method == 'bySlug') {
         $value = $limit;
     }
     if (substr_count($method, ':') > 0) {
         $tmp = explode(':', $method);
         $value = array_pop($tmp);
         $method = implode(':', $tmp);
     }
     if ($page < 1) {
         $page = 1;
     }
     if (empty($sort)) {
         $sort = [];
     }
     if (empty($fields)) {
         $fields = [];
     }
     $metadata = $this->model->collection($slug);
     if ($metadata === false) {
         throw new Exception('Can not load collection metadata for: ' . $slug);
     }
     $collection = new Collection($metadata, $this->root, $this->route, $this->db, $this->language, $this->person, $this->search);
     $collection->queryOptionsSet($limit, $page, $sort, $method, $value);
     return $collection;
 }