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

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?
Reply


Messages In This Thread
How can I make this controller DRY? - by Ajax30 - 01-30-2022, 01:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB