开发者

How to pass variables to classes in frontend/lib in symfony 1.4

My understanding of symfony isn't stellar sometimes. I just came across this problem and I'm really not sure how to pass a variable in this situation, and unfortunately not sure what to look into in order to better understand what I'm doing.

I can't use $this->getUser within the class as it's (apparently?) outside of the symfony schema, so storing it in the session is not an option.

I've tried different methods of passing the variable in, but... I think I'm just not doing it right due to not being clear o开发者_运维问答n how this exchange of information works in this situation.

The code is here, living in the folder apps/frontend/lib:

public function postCompletedForm( $campaign_id, $hp_affiliate_id, $params = array(), &$response )
{
  $params[ 'ip_address' ] = $_SERVER[ 'REMOTE_ADDR' ];
  if ( isset( $ip_override )) //this is what I need to pass in
  {
    $params[ 'ip_address' ] = $ip_override;
  }
  $params[ '__timestamp' ] = date( 'Y-m-d H:i:s' );

  $response = $this->sfWebBrowser->post( $this->api_endpoint . 'post/' . $campaign_id . '/' . $hp_affiliate_id . '/', $params )->getResponseText();
    return ( preg_match( '/(1<\/SUCCESS>)/', $response ) ) ? true : false;
}

It's used by an action in a module within frontend as well. It's really not a big job at all, and I know the answer will be painfully simple. I'm just not sure what to look for since what I know of php and the framework is failing me.

Thanks for any help! I apologize if this is kind of a ridiculous question. There are some aspects of php I have barely touched still, as strange as it is.


If You know that this code is going to be executed only in frontend app, You can always reach Your user class (and various others in similar way) with:

sfContext::getInstance()->getUser();

http://www.symfony-project.org/api/1_4/sfContext

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜