简体   繁体   English

ModX:在Wayfinder中使用PHP var?

[英]ModX: Use PHP var in Wayfinder?

I have a snippet which gets document IDs from the DB. 我有一个片段,从数据库中获取文档ID。

I want to out put these in a menu with Wayfinder but am having trouble getting it to work. 我想把它们放在带Wayfinder的菜单中,但是很难让它运行起来。 Does anyone know the correct way of placing a PHP var within Wayfinder? 有没有人知道在Wayfinder中放置PHP var的正确方法? Tried this but no luck: 试过这个,但没有运气:

echo '[[Wayfinder? &includeDocs=`' . $docid . '`]]';

(PS: using Revo) (PS:使用Revo)

EDIT: Added more code 编辑:添加更多代码

In a nut shell, my code gets a logged in users id from sessions and finds thier access group. 在一个坚果shell中,我的代码从会话中获取登录用户ID并找到他们的访问组。 Ultimate goal is to display links to resources that are within their access group. 最终目标是显示其访问组内的资源的链接。 This is the later part of the snippet where I have got the appropriate resource IDs and just need to out put them. 这是片段的后面部分,我有适当的资源ID,只需要输出它们。

//RETRIEVE DOCUMENT GROUPS RELATED TO ACCESS GROUPS
          $docgroups = "SELECT * FROM `modx_document_groups` WHERE `document_group` = '$target' ";

          $docstmt = $modx->query($docgroups );              

          while ($docrow = $docstmt->fetch(PDO::FETCH_ASSOC)) {
          $docid = $docrow['document'];            

          echo '[[Wayfinder? &startId=`0` &includeDocs=`' . $docid . '`]]';

          }//END

In modx, your snippets must return a value to access it in chunks/templates etc. This is one way: 在modx中,您的代码段必须返回一个值以便在块/模板等中访问它。这是一种方式:

//MySnippet
<?php
// logic
$docIDs = array(1, 2, 23, 17);
return implode(',', $docIDs);

and then your wayfinder call uses the snippet: 然后你的探路者电话使用该片段:

 // wayfinder call
[[!Wayfinder? &includeDocs=`[[!MySnippet]]`]]

// is the same as:
[[!Wayfinder? &includeDocs=`1,2,23,17`]]

The right way to do this at Modx Revolution : 在Modx Revolution上做到这一点的正确方法:

$c = $modx->newQuery('modResourceGroupResource');
$c->where(array( 'document_group' => $target ));
$docs = $modx->getCollection('modResourceGroupResource', $c);

$docids = array();
foreach($docs as $doc) {
    $docids[] = $doc->get('document');
}

$output = $modx->runSnippet('Wayfinder',array(
    'startId' => 0,
    'includeDocs' => implode(',', $docids);
));

return $output;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM