我在actions.class.php中有这段代码
public function executeListmatches(sfWebRequest $request)
{
$form_values = $request->getParameter('match_form', array());
global $gender_id2 = $form_values['gender2'];
global $age1 = $form_values['age1'];
$age2 = $form_values['age2'];
$province_id = $form_values['id'];
echo "in list matches ".$gender_id2." ".$age1." ".$age2." ".$province_id;
$this->pager = $this->setupPager();
$this->matching_rows = RcProfileTablePeer::getAllBySelection($gender_id2,$age1,$age2,$province_id);
return sfView::SUCCESS;
}
然后
protected function setupPager()
{
echo "in pager ".$gender_id2." ".$age1." ".$age2." ".$province_id;
$pager = new sfPropelPager('RcProfileTable', 10);
$pager->setCriteria(RcProfileTablePeer::getAllBySelection($GLOBALS['gender_id2'],$GLOBALS['age1'],$GLOBALS['age2'],$province_id));
$pager->setPage($this->getRequestParameter('page', 1));
$pager->init();
return $pager;
}
当我使用全局关键字时我得到并且错误:
PHP Parse error: syntax error, unexpected '=', expecting ',' or ';' in actions.class.php on line 41
当我使用$ GLOBALS ['gender_id2']时,该值为null 我需要设置一个寻呼机,因为我需要列出符合我选择标准的所有行
在RcProfileTablePeer中我有:
static public function getAllBySelection($gender2,$age1,$age2,$province_id)
{
echo $gender2." ".$age1." ".$age2." ".$province_id;
$criteria = new Criteria();
$criteria->add(RcProfileTablePeer::GENDER_ID,$gender2, Criteria::EQUAL);
$criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
$criteria->addAnd(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);
if ($province_id <> 10)
$criteria->addAnd(RcProfileTablePeer::PROVINCE_ID,$province_id, Criteria::EQUAL);
return self::doSelect($criteria);
}
请帮忙,我不知道我该怎么做。 谢谢
答案 0 :(得分:2)
您的代码中只有一个解析错误。 PHP解释器告诉你这个。您不能声明全局变量,并在一个语句中分配它。
global $gender_id2 = $form_values['gender2'];
必须是
global $gender_id2;
$gender_id2 = $form_values['gender2'];
除此之外,正如OZ_所说,不使用全局。