Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recommend the book "Zend Framework in Action" from Manning Publications as a great, up-to-date, introduction to this. It's available as PDF download, so you can have it now :)</p> <p>But to answer this particular question:</p> <p>Let's start by defining two key terms. The "Auth" in Zend_Auth refers to Authentication, which proves someone is who they say they are (i.e. login). The "A" in Zend_Acl refers to Authorization, which proves someone has the right to do what they're trying to do (i.e. access control).</p> <p>Assuming the user has a single role... Store the user's roles in the "identity" you get as part of Zend_Auth. At login:</p> <pre><code>$auth = Zend_Auth::getInstance(); $identity = new stdClass(); $identity-&gt;user_pk = $user-&gt;getPrimaryKey(); $identity-&gt;user_name = $user-&gt;getName(); $identity-&gt;role = $user-&gt;getRole(); // select * from user_role where user_pk=xxx $auth-&gt;getStorage()-&gt;write($identity); </code></pre> <p>In Controller:</p> <pre><code>$acl-&gt;add(new Zend_Acl_Resource('news')) -&gt;allow('defaultRole', 'news'); </code></pre> <p>Everything is denied by default, so you don't really need to specify: </p> <pre><code>-&gt;deny('defaultRole', 'news', 'add'); </code></pre> <p>Further on in the Controller's code:</p> <pre><code>$identity = Zend_Auth::getInstance()-&gt;getIdentity(); if(!$acl-&gt;isAllowed($identity-&gt;role, 'news', 'add')) { header('Location: http://www.yoursite.com/error/unauthorized'); } </code></pre> <p>If the user's identity is not allowed to do "news->add", it will redirect them to the unauthorized page (assuming you've made such a page).</p> <p>If the user had >1 role, you'd store an array of roles in their identity. Then your check would go something like this:</p> <pre><code>$identity = Zend_Auth::getInstance()-&gt;getIdentity(); $isAllowed = false; foreach($identity-&gt;role as $role) { if($acl-&gt;isAllowed($role, 'news', 'add')) { $isAllowed = true; } } if(!$isAllowed) { // if NO ROLES have access, redirect to unauthorized page header('Location: http://www.yoursite.com/error/unauthorized'); } </code></pre> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload