开发者

MODX parse error function implode (is it me or modx?)

开发者 https://www.devze.com 2023-01-01 09:42 出处:网络
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

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


I think your problem lies here :

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消