problem with using $GLOBALS and global keyword
i have this code in 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;
}
and then
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;
}
when i use the global keyword i get and error:
PHP Parse error: syntax error, unexpected '=', expecting ',' or ';' in actions.class.php on line 41
when i use $GLOBALS['gender_id2'] the value is null i need to setup a pager because i need to list all rows that matches my selection criteria
in RcProfileTablePeer i have:
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);
}
please help, i dont know how else i must do this. thank you
There just is a parse error in your code. The PHP interpreter tells you this. You can't declare a global variable, and assign it in one statement.
global $gender_id2 = $form_values['gender2'];
must be
global $gender_id2;
$gender_id2 = $form_values['gender2'];
Other than that, as OZ_ already stated, don't use globals.
精彩评论