2011-04-25 75 views
0

谁能告诉我如何在控制器中正确地格式化查询。帮助需要在Zend Framework中格式化原则查询

目前它在我的FilteringSelect中没有提供任何内容。但是,如果我将其更改为> =,我还会返回所有不正确的kennelID,但至少我得到了一些东西。

我测试过,会话变量已设置,并且可以确认有匹配容量的狗舍。

// Create autocomplete selection for the service of this booking 
    public function servkennelAction() 
    { 
    $sessionKennelBooking = new Zend_Session_Namespace('sessionKennelBooking'); 
    // disable layout and view rendering 
$this->_helper->layout->disableLayout(); 
$this->getHelper('viewRenderer')->setNoRender(true); 

// get list of grooming services for dogs from the table 
$qry= Doctrine_Query::create() 
    ->from('PetManager_Model_Kennels k'); 

     //This should be set by default and narrows down the search criteria 
     if(isset($sessionKennelBooking->numPets)){ 
      $b=(int)$sessionKennelBooking->numPets;        
      $qry->addWhere('k.capacity = ?','$b'); 
      } 

    $result=$qry->fetchArray(); 

    //generate and return JSON string using the primary key of the table 
    $data = new Zend_Dojo_Data('kennelID',$result); 
    echo $data->toJson(); 
} 

非常感谢提前。

格雷厄姆

回答

0

我认为addWhere条件是错误的。它必须是:

$qry->addWhere('k.capacity = ?', $b); 

即$ b不带引号。

+0

你是对的。谢谢ischenkodv – Graham 2011-04-25 12:08:12