2011-10-27 3 views
1

generator.ymlで設定されているdoJoinメソッドにリクエストオブジェクトを渡すにはどうしたらいいですか?generator.ymlで定義されたメソッドにrequestオブジェクトをtable_methodで渡す方法

にgenerator.yml:

generator: 
    param: 
    config: 
     list:  
     table_method: doJoin 

ItemTable.class.php:あなたが使用することができます

public static function doJoin(Doctrine_Query $q) 
{ 
    $rootAlias = $q->getRootAlias($q); 

    return $q->select($rootAlias.'.*, p.currency_code, p.customer_price') 
     ->innerJoin($rootAlias.'.Price p') 
     ->where('p.currency_code = \'USD\''); 

} 

答えて

1

あなたはactions.class方法buildQuery()をオーバーライドすることができます。 PHPは、要求パラメータを受け入れる...->$table_method($query, $this->getRequest()

protected function buildQuery() 
{ 
    $tableMethod = $this->configuration->getTableMethod(); 
    $query = Doctrine::getTable('CLASS_NAME') 
    ->createQuery('a'); 

    if ($tableMethod) 
    { 
    $query = Doctrine::getTable('CLASS_NAME')->$table_method($query, $this->getRequest()); 
    } 

    $this->addSortQuery($query); 

    $event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_query'), $query); 
    $query = $event->getReturnValue(); 

    return $query; 
} 

次にあなたがItemTable.class.phpを変更:

public static function doJoin(Doctrine_Query $q, sfWebRequest $request) 
+0

エラー:クラスCLASS_NAMEを見つけることができませんでした –

+0

'クラス'の実名で 'CLASS_NAME'を変更する必要があります。 – samura

+0

はい、私は行いましたが、他にも多くのエラーがありました。 –

0

sfContext::getInstance()->getRequest()->getParameter('whatever_you_want'); 
+0

フム...それはnullを返します:sfContextの::のgetInstance() - >のGetRequest() - >のgetParameter( 'main_item.filters')。ご覧のとおり、フィルターから値を取得しようとしています。 –

関連する問題