Welcome Guest, Not a member yet? Register   Sign In
How can I make this controller DRY?

I have been working on an online newspaper/blogging application with CodeIgniter 3.1.8 and Twitter Bootstrap 4. I am currently working on a lazy loading (of posts) feature.

I have added a pager option for the posts, to replace the pagination, if desired.

The code in the controller responsible for this is:

PHP Code:
if ($this->Static_model->get_static_data()['has_pager']) {
      $config['display_pages'] = FALSE;
      $config['first_link'] = FALSE;
      $config['last_link'] = FALSE;
      $config['prev_tag_open'] = '<li class="prev">';
      $config['prev_tag_close'] = '</li>';
      $config['next_tag_open'] = '<li class="next">';
      $config['next_tag_close'] = '</li>';
The problem is that it appears twice in the Posts controller alone and it also appears in other controllers (Categories, for instance) See the applications GitHub repo here

What is the most effective and DRY way to "externalize" the pager functionality (and the code above) and call it with a small piece of code, where it is nedded?

At first glance, I will suggest you move the code to a helper OR a separate controller OR another library that extends the default CI3 pagination library.

That way, you can load the file wherever it is needed.

Theme © iAndrew 2016 - Forum software by © MyBB