S
S
semki0962016-02-19 23:10:02
CodeIgniter
semki096, 2016-02-19 23:10:02

How to correctly display the menu (using codeigniter as an example)?

I need to display a menu that only the admin will see. Naturally, I check that this is the admin, and display the menu, everything happens in the controller:

$this->load->view('templates/header', $data);

if ($this->ion_auth->logged_in() and $this->ion_auth->is_admin())
{
     $user = $this->ion_auth->user()->row();
      $this->load->view('admin/admin_menu');
}

$this->load->view('news/view', $data);
$this->load->view('templates/footer');

But the problem is that I have a lot of controllers and functions, and I thought that in order not to write the check and output of the admin menu in each, it's better to place this code in one place - namely in view('templates/header'), right there wrote:
if ($this->ion_auth->logged_in() and $this->ion_auth->is_admin())
{
     $user = $this->ion_auth->user()->row();
     $this->load->view('admin/admin_menu');
 }

But doubts torment me, is it right to place in the view what should be placed in the controller? Is it possible to do this better and easier?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Silm, 2016-02-19
@Silm

Nothing criminal. Checking ok, then it’s more correct to call some kind of controller that will return the menu itself. But even so, the norms, if you do not want to somehow expand this business.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question