使用旧的旧式引导程序将Zend_Navigation添加到视图中 [英] Add Zend_Navigation to the View with old legacy bootstrap

查看:84
本文介绍了使用旧的旧式引导程序将Zend_Navigation添加到视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整个周末我一直在与Zend_Navigation斗争,但现在我遇到了另一个问题,我认为这是造成我很多问题的原因.

I've been struggling with Zend_Navigation all weekend, and now I have another problem, which I believe has been the cause of a lot of my issues.

我正在尝试将Zend_Navigation添加到旧版1.7.6 Zend Framework应用程序中,我已将Zend库更新为1.9.0,并更新了引导程序以允许此库更新.

I am trying to add Zend_Navigation to a legacy 1.7.6 Zend Framework application, i've updated the Zend Library to 1.9.0 and updated the bootstrap to allow this library update.

问题是我不知道如何,示例显示了如何将Navigation对象添加到视图的新引导方法,我已经尝试过:

The problem is that I don't know how, and the examples show the new bootstrap method of how to add the Navigation object to the view, I've tried this:

//initialise the application layouts with the MVC helpers
$layout = Zend_Layout::startMvc(array('layoutPath' => '../application/layouts'));

$view = $layout->getView();
$configNav = new Zend_Config_Xml('../application/config/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($configNav);
$view->navigation($navigation);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view); 

这似乎运行良好,但是当我在布局中使用面包屑视图帮助程序时,出现以下错误:严格标准:从C:\ www \ moobia \ development \中的空值创建默认对象第27行上的website \ application \ modules \ employers \ controllers \ IndexController.php

This seems to run through fine, but when I go to use the breadcrumb view helper in my layout, it errors with: Strict Standards: Creating default object from empty value in C:\www\moobia\development\website\application\modules\employers\controllers\IndexController.php on line 27

这是由控制器的init()函数中的以下代码引起的.

This is caused by the following code in the init() function of my controller.

$uri = $this->_request->getPathInfo();
$activeNav = $this->view->navigation()->findByUri($uri); <- this is null when called
$activeNav->active = true;

我相信是因为Zend_Navigation对象不在视图中.

I believe it's because the Zend_Navigation object is not in the view.

我会考虑将引导程序迁移到当前方法,但是目前我没有足够的时间来发布.

I would look at migrating the bootstrap to the current method, but at present I am running out of time for a release.

谢谢

赠予

推荐答案

首先,您需要确定您对Zend_Navigation是否不在视图中的怀疑是否正确.最简单的方法是添加:

First you need to work out whether your suspicion that Zend_Navigation is not in the view is correct. Easiest way to do this would be to add:

var_dump($this->view->navigation());exit;

到您的控制器init().如果存在Zend_Navigation对象,它将返回该对象.

to your controller init(). This should return the Zend_Navigation object if it's there.

如果不存在,提供Zend_Navigation对象的另一种方法是使用注册表,这可能会更容易.为此,您需要从引导程序中删除视图内容,然后执行以下操作:

If it's not there, an alternative way of supplying the Zend_Navigation object is to use the registry, which might be easier. To do this you'd remove the view stuff from your bootstrap and just do this:

$configNav = new Zend_Config_Xml('../application/config/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($configNav);
Zend_Registry::set('Zend_Navigation', $navigation);

如果尚未包含Zend Navigation对象,则控制器init()的内容将与视图对象在注册表中的显示相同.

your controller init() stuff would remain the same as the view object will look in the registry if it doesn't already have a Zend Navigation object.

但是,我不确定您的控制器init()代码是否可以按照您想要的方式正常工作.我认为findByUri()不能在Mvc页面上工作(但是我可能错了),从您先前的问题来看,您XML文件中的大多数页面看起来都是Mvc页面. Mvc类具有"href"属性,该属性似乎是等效的.如果您的XML文件包含这两种页面类型,则可能需要同时检查这两种类型,因此我建议使用类似的方法:

However, I'm not sure that your controller init() code will quite work the way that you want. I don't think findByUri() will work on Mvc pages (but I could be wrong), and from your previous question it looked like most of the pages in your XML file are Mvc ones. The Mvc class has an 'href' property which appears to be the equivalent. If your XML file contains both page types, you might need to check both, so I'd suggest something like this:

$uri = $this->_request->getPathInfo();
if (($activeNav = $this->view->navigation()->findByHref($uri)) !== null) {
    $activeNav->active = true;
} else if (($activeNav = $this->view->navigation()->findByUri($uri)) !== null) {
    $activeNav->active = true;
}

这篇关于使用旧的旧式引导程序将Zend_Navigation添加到视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆