phpzend-frameworkaclzend-navigationzend-acl

Zend Navigation privileges without Zend ACL's


Ok, I have a code that generates a xml file like the following:

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
    <nav>
        <main>
            <label>Home</label>
            <alias>main</alias>
            <uri>/</uri>
            <privilege>
                <super_admin>super_admin</super_admin>
                <reg_user>reg_user</reg_user>
            </privilege>
            <status>active</status>
            <sprite>sprite.png</sprite>
            <pages>
                <article>
                    <label>Article</label>
                    <alias>article</alias>
                    <uri>/article</uri>
                    <privilege>
                        <super_admin>super_admin</super_admin>
                        <reg_user>reg_user</reg_user>
                    </privilege>
                    <status>active</status>
                    <pages>
                        <insert>
                            <label>Insert</label>
                            <alias>insert</alias>
                            <uri>/article/insert</uri>
                            <privilege>
                                <super_admin>super_admin</super_admin>
                            </privilege>
                            <status>active</status>
                        </insert>
                        [...]
                    </pages>
                </article>
                [...]
            </pages>
        </main>
    </nav>
</configdata>

My problem is that my URI's are not in the form of a Zend Acl because I followed this link that helped me getting all my URI's, manage the privileges of each group (named as super_admin and reg_user on the code above) and save them on the Database.

The problem is that now, I want to render a menu with only the specific items that are accessable to a specific group. This means that, using the above XML, if I enter with a super_admin, I would have a menu like this:

- Home
    - Article
        - Insert

And if I enter with a reg_user, my menu should be:

- Home
    - Article

How can I do this?

I'm using Zend Framework 1.11.x


Solution

  • If you want to do it without Zend ACL I suggest to write own partial for menu. Then you check current user role (stored maybe in Zend_Registry) with menu item privilege from xml file.

    Here you can see how to use custom menu partial https://stackoverflow.com/a/1255289/760866

    You read custom xml properties like this:

    $properties = new Zend_Config($page->GetCustomProperties());
    $privilege = $properties->privilege;
    

    Hope that helps!