-1

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

charlie_cat
  • 1,830
  • 7
  • 44
  • 73
  • 2
    Don't use globals at all, [read here](http://stackoverflow.com/questions/5166087/global-in-functions/5166527#5166527) why. – OZ_ Sep 12 '11 at 07:33
  • You should consider reformulating the question as to why you are resorting to globals, as in any acase there are more appropriate solutions around. – Gerry Sep 12 '11 at 14:10

1 Answers1

2

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.

Rijk
  • 11,032
  • 3
  • 30
  • 45
  • okey dokey,thank you so i can use the global keyword just not $GLOBALS? – charlie_cat Sep 12 '11 at 07:44
  • 1
    @Helloise Smit, it's like shoot yourself in the foot - you can, of course, but it's not a good decision. – OZ_ Sep 12 '11 at 07:47
  • how else will i tackle this problem then if i cant use global/$GLOBALS? i need to set up the pager to know how many pages?? thus i need to call getAllBySelection(). i seriously dont know how to get round this issue..please help me? thanks – charlie_cat Sep 12 '11 at 08:00
  • @Helloise Smit, require these variables in the list of function's arguments. – OZ_ Sep 12 '11 at 08:04
  • i did try that: $this->pager = $this->setupPager($gender_id2,$age1,$age2,$province_id); but then get error: Fatal error: __clone method called on non-object in /usr/share/php/symfony/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php on line 50 – charlie_cat Sep 12 '11 at 08:30