Controlling User Privileges in Codeigniter

萝らか妹 提交于 2019-12-06 14:56:46

You most definitely do not need to create separate controllers and views.

You can just store the users privilege type (1 or 2) in a session and then do a check in each of your controllers or views to check the privileges for the user.

an example of a nav in a view file

<div id="nav">
  <ul>
    <li>Home</li>
    <li>Logout</li>
    <?php if($this->session->userdata('privilege') == 1) : ?>
      <li>Delete</li>
    <?php endif; ?>
  </ul>
</div>

You can perform the same kind of check in your controller to make sure that the users access is appropriate to perform some function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!