MODX 解析错误函数内爆(是我还是 modx?)

发布于 2024-09-03 13:08:13 字数 2125 浏览 12 评论 0原文

2010 年 6 月 4 日更新:这似乎是 MODx v 1.0.3 中的一个错误,与 implode 函数无关,而是结果过滤器子句中数据类型不匹配的问题。已向 JIRA 提交错误:MODX-2035。

嗨,我一生都无法弄清楚这一点,也许有人可以提供帮助。

使用 MODX,表单采用用户条件来创建过滤器并返回文档列表。该表单由一个文本字段和几个复选框组成。如果文本字段和复选框数据都已发布,则该功能可以正常工作;如果仅发布复选框数据,则该功能可以正常工作;但如果只发布文本字段数据,modx 会给出以下错误:

错误:implode() [function.implode]:传递的参数无效。

我已经在 modx 之外使用平面文件对此进行了测试,一切正常,这让我假设 modx 中存在错误。但我不相信。这是我的代码:

<?php
$order = array('price ASC'); //default sort order  
if(!empty($_POST['tour_finder_duration'])){ //duration submitted  
 $days = htmlentities($_POST['tour_finder_duration']); //clean up post  
 array_unshift($order,"duration DESC"); //add duration sort before default  
 $filter[] = 'duration,'.$days.',4'; //add duration to filter[] (field,criterion,mode)  
 $criteria[] = 'Number of days: <strong>'.$days.'</strong>'; //displayed on results page  
}  

if(!empty($_POST['tour_finder_dests'])){ //destination/s submitted  
 $dests = $_POST['tour_finder_dests'];  
 foreach($dests as $value){ //iterate through dests array  
  $filter[] = 'searchDests,'.htmlentities($value).',7'; //add dests to filter[]  
  $params['docid'] = $value;  
  $params['field'] = 'pagetitle';  
  $pagetitle = $modx->runSnippet('GetField',$params);  
  $dests_array[] = '<a href="[~'.$value.'~]" title="Read more about '.$pagetitle.'"     class="tourdestlink">'.$pagetitle.'</a>';  
 }  
 $dests_array = implode(', ',$dests_array);  
 $criteria[] = 'Destinations: '.$dests_array; //displayed on results page  
}  

if(is_array($filter)){  
 $filter = implode('|',$filter);//pipe-separated string  
}  
if(is_array($order)){  
 $order = implode(',',$order);//comma-separated string  
}  
if(is_array($criteria)){  
 $criteria = implode('<br />',$criteria);  
}  

echo '<br />Order: '.$order.'<br /> Filter: '.$filter.'<br /> Criteria: '.$criteria;

//next: extract docs using $filter and $order, display user's criteria using $criteria...  
?>

echo 语句显示在 MODX 错误消息上方,并且 $filter 数组已正确内爆。

任何帮助都会阻止我的电脑飞出窗外。

谢谢

Update 4-June-2010: This appears to be a bug in MODx v 1.0.3, nothing to do with the implode function but rather a problem with mis-matched datatypes in the resulting filter clause. Bug has been filed with JIRA: MODX-2035.

Hi, I cannot for the life of me figure this out, maybe someone can help.

Using MODX a form takes user criteria to create a filter and return a list of documents. The form is one text field and a few checkboxes. If both text field and checkbox data is posted, the function works fine; if just the checkbox data is posted the function works fine; but if just the text field data is posted, modx gives me the following error:

Error: implode() [function.implode]: Invalid arguments passed.

I've tested this outside of modx with flat files and it all works fine leading me to assume a bug exists within modx. But I'm not convinced. Here's my code:

<?php
$order = array('price ASC'); //default sort order  
if(!empty($_POST['tour_finder_duration'])){ //duration submitted  
 $days = htmlentities($_POST['tour_finder_duration']); //clean up post  
 array_unshift($order,"duration DESC"); //add duration sort before default  
 $filter[] = 'duration,'.$days.',4'; //add duration to filter[] (field,criterion,mode)  
 $criteria[] = 'Number of days: <strong>'.$days.'</strong>'; //displayed on results page  
}  

if(!empty($_POST['tour_finder_dests'])){ //destination/s submitted  
 $dests = $_POST['tour_finder_dests'];  
 foreach($dests as $value){ //iterate through dests array  
  $filter[] = 'searchDests,'.htmlentities($value).',7'; //add dests to filter[]  
  $params['docid'] = $value;  
  $params['field'] = 'pagetitle';  
  $pagetitle = $modx->runSnippet('GetField',$params);  
  $dests_array[] = '<a href="[~'.$value.'~]" title="Read more about '.$pagetitle.'"     class="tourdestlink">'.$pagetitle.'</a>';  
 }  
 $dests_array = implode(', ',$dests_array);  
 $criteria[] = 'Destinations: '.$dests_array; //displayed on results page  
}  

if(is_array($filter)){  
 $filter = implode('|',$filter);//pipe-separated string  
}  
if(is_array($order)){  
 $order = implode(',',$order);//comma-separated string  
}  
if(is_array($criteria)){  
 $criteria = implode('<br />',$criteria);  
}  

echo '<br />Order: '.$order.'<br /> Filter: '.$filter.'<br /> Criteria: '.$criteria;

//next: extract docs using $filter and $order, display user's criteria using $criteria...  
?>

The echo statement is displayed above the MODX error message and the $filter array is correctly imploded.

Any help will save my computer from flying out the window.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

相权↑美人 2024-09-10 13:08:13

我认为你的问题在于:

$dests_array = implode(', ',$dests_array); 

如果 $dests 为空,$dest_array 可能为空,甚至没有初始化。

I think your problem lies here :

$dests_array = implode(', ',$dests_array); 

$dest_array may be empty and not even initialized if $dests is empty.

℉服软 2024-09-10 13:08:13

这确实应该发布在 MODx 论坛中。我喜欢 stackoverflow,但 MODx 更小众。

This really should be posted in the MODx forums. I love stackoverflow, but MODx is more niche.

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