我正在开发一个小型博客应用程序。后端和前端之间有明显的分隔。
后端是由Codeigniter 3制成的API,它吐出页面,帖子,分页等。>>
在此API中,类别
控制器显示[按类别发布:”public function posts($path, $category_id) { //load and configure pagination $this->load->library('pagination'); $config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . $path; $config['base_url'] = base_url('/categories/posts/' . $category_id); $config['query_string_segment'] = 'page'; $config['total_rows'] = $this->Posts_model->get_num_rows_by_category($category_id); $config['per_page'] = 12; if (!isset($_GET[$config['query_string_segment']]) || $_GET[$config['query_string_segment']] < 1) { $_GET[$config['query_string_segment']] = 1; } $limit = $config['per_page']; $offset = ($this->input->get($config['query_string_segment']) - 1) * $limit; $this->pagination->initialize($config); $data = $this->Static_model->get_static_data(); $data['pagination'] = $this->pagination->create_links(); $data['pages'] = $this->Pages_model->get_pages(); $data['categories'] = $this->Categories_model->get_categories(); $data['category_name'] = $this->Categories_model->get_category($category_id)->name; $data['posts'] = $this->Posts_model->get_posts_by_category($category_id, $limit, $offset); // All posts in a CATEGORY $this->output->set_content_type('application/json')->set_output(json_encode($data,JSON_PRETTY_PRINT)); }
上面的代码有一个错误,原因是我找不到。应用程序引发的错误消息是:
Missing argument 2 for Categories::posts()
我的错误在哪里?
我正在开发一个小型博客应用程序。后端和前端之间有明显的分隔。后端是一个由Codeigniter 3制成的API,它吐出页面,帖子,...
这意味着您已经向该方法传递了1个参数而不是2个参数。发送$path
和$category_id
,或者如果您想说有时第二个参数可能不存在,请像下面这样重写:
public function posts($path, $category_id = null) {