如何将 PHP 动态变量传递到 XML 文件
我正在尝试生成菜单,为此,我使用 navigation.xml (Zend Framework)
Contents of navigation.xml(file)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<page1>
<pages>
<label>test</label>
<uri>abc.php</uri> </pages><page1></nav></config>
并在控制器中,我正在读取 config.xml 文件,如下所示
$config = new Zend_Config_Xml('/configuration/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->getHelper('navigation')->setContainer($container);
在上面的 XML 文件中 如何将动态值传递给“abc.php?param1” =".$参数值 如果从 XML 文件中不可能,我如何通过从 navigation.xml 获取 Url 来从控制器传递 并且仅当正确的参数为时,该页面 abc.php 才会被激活 如果没有通过,它将被重定向到
视图中的default.php,我只是说 echo $this->navigation()->menu()->render();它将页面显示为,每个页面都需要附加一个参数才能传输到适当的位置。所以我的问题是如何将动态参数附加到来自 navigation.xml 的每个链接,
我正在做的是获取页面作为标签 如果页面的值为“myPage”,那么我将设置新的 URI 页面符合预期
$it = new RecursiveIteratorIterator(
$container, RecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $page) {
$label = $page->label;
if($label = "MyPage"){
$newuri = "mypage.php?stcode=".$stcode."&cde=".$cde;
$page->setUri($newuri);
}
}
Now my problem and all the menu items in the menu are getting the same URI .
i dont know what wrong iam doing
Iam trying to generate the menu and For that iam using navigation.xml (Zend Framework)
Contents of navigation.xml(file)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<page1>
<pages>
<label>test</label>
<uri>abc.php</uri> </pages><page1></nav></config>
and in the controller iam reading the config.xml file as follows
$config = new Zend_Config_Xml('/configuration/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->getHelper('navigation')->setContainer($container);
In the Above XML file How do i pass the dynamic value to "abc.php?param1=".$paramvalue
if Not possible from XML file How do I pass from the Controller by taking the Url from navigation.xml And that page abc.php gets activated only if the right parameter is
passed if not it will be redirected to default.php
in the View iam just saying echo $this->navigation()->menu()->render(); it displays the pages as and each page needs to have a parameter appended to it in order to be transferred to appropriate location.So My problem is how to append the dynamic parameter to each link coming from navigation.xml
what iam doing is getting the page as label
if the page has the value "myPage" than then iam setting the new URI
with the page as expected
$it = new RecursiveIteratorIterator(
$container, RecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $page) {
$label = $page->label;
if($label = "MyPage"){
$newuri = "mypage.php?stcode=".$stcode."&cde=".$cde;
$page->setUri($newuri);
}
}
Now my problem and all the menu items in the menu are getting the same URI .
i dont know what wrong iam doing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你想要实现什么,但你可以为 MVC 页面设置参数,如下所示:
或者:
然后你可以通过以下方式找到它:
你可以使用
RecursiveIterator
来迭代所有页面容器,找到您需要的并更新它(例如在控制器插件中)。I'm not sure what are you trying to achieve, but you may set params for MVC pages like that:
or:
Then you may find it by:
You may use
RecursiveIterator
to iterate all the page containers, to find the one you need and update it (eg. in controller plugin).