-
Ajax30 Member
  
-
Posts: 71
Threads: 46
Joined: Aug 2017
Reputation:
0
I am working on a blog application in Codeigniter 3.1.8.
I have a Posts controller at
Quote:application/controllers/Posts.php
I have a Categories controller at
Quote:application/controllers/Categories.php
In the Posts controller I have:
Code: public function index() {
$this->load->library('pagination');
$config = [
'base_url' => base_url("/posts"),
'page_query_string' => TRUE,
'query_string_segment' => 'page',
'display_pages' => TRUE,
'use_page_numbers' => TRUE,
'per_page' => 12,
'total_rows' => $this->Posts_model->get_num_rows(),
'uri_segment' => 3,
'first_link' => '«',
'first_tag_open' => '<li>',
'first_tag_close' => '</li>',
'last_link' => '»',
'last_tag_open' => '<li>',
'last_tag_close' => '</li>',
'full_tag_open' => '<ul class="pagination">',
'full_tag_close' => '</ul>',
'next_link' => '›',
'next_tag_open' => '<li>',
'next_tag_close' => '</li>',
'prev_link' => '‹',
'prev_tag_open' => '<li>',
'prev_tag_close' => '</li>',
'num_tag_open' => '<li>',
'num_tag_close' => '</li>',
'cur_tag_open' => '<li class="active"><span>',
'cur_tag_close' => '</span></li>'
];
// More code
}
The
array in the Categories controller is almost the same:
Code: public function posts($id) {
$this->load->library('pagination');
$config = [
'base_url' => base_url('/categories/posts/' . $id),
'page_query_string' => TRUE,
'query_string_segment' => 'page',
'display_pages' => TRUE,
'use_page_numbers' => TRUE,
'per_page' => 12,
'total_rows' => $this->Posts_model->get_num_rows_by_category($id),
'uri_segment' => 3,
'first_link' => '«',
'first_tag_open' => '<li>',
'first_tag_close' => '</li>',
'last_link' => '»',
'last_tag_open' => '<li>',
'last_tag_close' => '</li>',
'full_tag_open' => '<ul class="pagination">',
'full_tag_close' => '</ul>',
'next_link' => '›',
'next_tag_open' => '<li>',
'next_tag_close' => '</li>',
'prev_link' => '‹',
'prev_tag_open' => '<li>',
'prev_tag_close' => '</li>',
'num_tag_open' => '<li>',
'num_tag_close' => '</li>',
'cur_tag_open' => '<li class="active"><span>',
'cur_tag_close' => '</span></li>'
];
}
How could I make a "base" $config array which, for every controller it is used in, I would only have to write what is specific?
|