如何将 PHP 动态变量传递到 XML 文件

发布于 2024-09-16 23:36:34 字数 1408 浏览 5 评论 0原文

我正在尝试生成菜单,为此,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芸娘子的小脾气 2024-09-23 23:36:34

我不确定你想要实现什么,但你可以为 MVC 页面设置参数,如下所示:

<page1>
<pages>
<label>test</label>
<params>
<param1>param1value</param1>
<myparam2>myparam2value</myparam2>
</params>

或者:

<page1>
<pages>
<label>test</label>
<uri>abc.php?param1=val</uri>

然后你可以通过以下方式找到它:

$page = $container->findOneByLabel('test');
$page->setUri($yourNewUri);

你可以使用 RecursiveIterator 来迭代所有页面容器,找到您需要的并更新它(例如在控制器插件中)。

I'm not sure what are you trying to achieve, but you may set params for MVC pages like that:

<page1>
<pages>
<label>test</label>
<params>
<param1>param1value</param1>
<myparam2>myparam2value</myparam2>
</params>

or:

<page1>
<pages>
<label>test</label>
<uri>abc.php?param1=val</uri>

Then you may find it by:

$page = $container->findOneByLabel('test');
$page->setUri($yourNewUri);

You may use RecursiveIterator to iterate all the page containers, to find the one you need and update it (eg. in controller plugin).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文