phpzend-frameworkzend-navigation

Zend_Navigation failing to load


Following on from my earlier question, I am still having issues with loading the xml file into Zend_Navigation.

I am now getting the following error message:

<b>Fatal error</b>:  Uncaught exception 'Zend_Navigation_Exception' with message 'Invalid argument: Unable to determine class to instantiate' in C:\www\mysite\development\website\library\Zend\Navigation\Page.php:223

I've tried to make my navigation.xml file look similar to the example on the Zend Documentation, However I just can't seem to get it to work. My XML file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
 <navigation>

    <default>
        <label>Home</label>
        <controller>index</controller>
        <action>index</action>
        <module>default</module>
        
        <pages>
            <tour>
                <label>Tour</label>
                <controller>tour</controller>
                <action>index</action>
                <module>default</module>
            </tour>
            
            <blog>
                <label></label>
                <uri>http://blog.mysite.com</uri>                   
            </blog>
            
            <support>
                <label>Support</label>
                <controller>support</controller>
                <action>index</action>
                <module>default</module>
            </support>
        </pages>
     </default>
     
     <users>
        <label>Home</label>
        <controller>index</controller>
        <action>index</action>
        <module>users</module>
        <role>guser</role>
        <resource>owner</resource>
        
        <pages>
            
            <jobmanger>
                <label>Job Manager</label>
                <controller>jobmanager</controller>
                <action>index</action>
                <module>users</module>
                <role>guser</role>
                <resource>owner</resource>
            </jobmanger>
            
            <myaccount>
                <label>My Account</label>
                <controller>profile</controller>
                <action>index</action>
                <role>guser</role>
                <resource>owner</resource>
                <module>users</module>
                <pages>
                    
                    <detail>
                        <label>Account Details</label>
                        <controller>profile</controller>
                        <action>detail</action>
                        <module>users</module>
                        <role>guser</role>
                        <resource>owner</resource>
                        
                        <pages>
                            <history>
                                <label>Account History</label>
                                <controller>profile</controller>
                                <action>history</action>
                                <module>users</module>
                                <role>guser</role>
                                <resource>owner</resource>
                            </history>
                            
                            <password>
                                <label>Change Password</label>
                                <controller>profile</controller>
                                <action>changepwd</action>
                                <module>users</module>
                                <role>employer</role>
                                <resource>employers</resource>
                            </password>
                        </pages>
                    </detail>

...
</navigation>
</configdata>

I am loading this xml into the bootstrap as follows:

 $configNav = new Zend_Config_Xml('../application/config/navigation.xml', 'navigation');
 $navigation = new Zend_Navigation($configNav);
 $navView->navigation($navigation);

Now I confess that I've totally got the wrong end of the stick with this, but rapidly running out of ideas, and it's been a long week.

Thanks,

Grant


Solution

  • Zend_Navigation appears to determine whether or not to use an Mvc page or Uri page by checking for the existence of either the controller, action and module keys; or a uri key. The error you're reporting is generated if neither of these conditions are met. All of the examples in your XML document look fine, so I would guess that a some point later in the XML file you are missing one of the required keys for one of your pages. E.g. you have an action and controller but no module.

    If you aren't able to spot which one is causing the problem, I would suggest temporarily adding a debug line to Zend_Navigation by inserting:

    var_dump($options);exit;
    

    into line 222 of Zend/Navigation/Page.php. This would print out the keys for the element that is causing the error, which should help you work out which one in your XML doc it is. Remove this line again once you've fixed it!