Php 使用$GLOBALS和global关键字时出现问题
我在actions.class.php中有这段代码Php 使用$GLOBALS和global关键字时出现问题,php,symfony1,Php,Symfony1,我在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'];
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);
}
请帮帮我,我不知道我还能怎么做。
谢谢您的代码中有一个解析错误。PHP解释器告诉您这一点。不能在一个语句中声明全局变量并赋值
global $gender_id2 = $form_values['gender2'];
一定是
global $gender_id2;
$gender_id2 = $form_values['gender2'];
<> P>除了OZI已经说过的,不要使用Global。< /P>根本不使用全局,为什么?你应该考虑重新讨论为什么你要求助于全局,因为在任何一个ACCESS中都有更合适的解决方案。OKEY DoKy,谢谢你,所以我可以使用全局关键字而不是$Global?@ HelloiSmith,这就像是对自己的脚开枪-当然可以,但这不是一个好决定。如果我不能使用global/$GLOBALS,我将如何解决这个问题?我需要设置寻呼机来知道有多少页??因此,我需要调用getAllBySelection。我真的不知道如何回避这个问题请帮帮我好吗?thanks@HelloiseSmit,在函数参数列表中需要这些变量。我尝试过:$this->pager=$this->setupPager$gender\u id2、$age1、$age2、$province\u id;但随后得到错误:致命错误:\在第50行的/usr/share/php/symfony/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php中对非对象调用了clone方法