需要帮助格式化Zend Framework中的Doctrine Query

时间:2011-04-25 10:50:09

标签: zend-framework doctrine

任何人都可以告诉我如何在我的控制器中正确格式化下面的查询。

目前它在我的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();
}

非常感谢提前。

格雷厄姆

1 个答案:

答案 0 :(得分:0)

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

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

即。 $ b没有引号。

相关问题