2010-08-31 105 views
1

我想實現我的模型這個方法:Zend框架選擇加入錯誤getTable()

class Application_Model_MenuProfilesProducts extends Zend_Db_Table_Abstract 
{ 
    protected $_name = 'menu_profiles_products'; 

    public function fetchProducts($profileID) { 
     $select = Zend_Db_Table::getDefaultAdapter()->select() 
         ->from(array('mpp' => 'menu_profiles_products'), array('NAME' => 'p.name', 'PRICE' => 'p.price*mp.added_value/100')) 
         ->join(array('p' => 'products'), 'p.id = mpp.product_id') 
         ->join(array('mp' => 'menu_profiles'), 'mp.id = mpp.profile_id') 
         ->where('mpp.profile_id = ?', $profileID); 

     $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); 
     return $adapter; 
    } 
} 

我得到一個錯誤無法識別的方法 'getTable()'

基本上我努力實現這個SQL查詢:

SELECT p.name as NAME, p.price*mp.added_value/100 AS PRICE 
FROM `menu_profiles_products` AS mpp 
JOIN products AS p ON p.id = mpp.product_id 
JOIN menu_profiles AS mp ON mp.id = mpp.profile_id 
WHERE mpp.profile_id = <a number> 

堆棧跟蹤轉儲從Zend公司:

#0 [internal function]: Zend_Db_Select->__call('getTable', Array) 
#1 D:\wamp\www\Bucatarie\library\Zend\Paginator\Adapter\DbTableSelect.php(46): Zend_Db_Select->getTable() 
#2 D:\wamp\www\Bucatarie\library\Zend\Paginator.php(755): Zend_Paginator_Adapter_DbTableSelect->getItems(0, 25) 
#3 D:\wamp\www\Bucatarie\library\Zend\Paginator.php(584): Zend_Paginator->getItemsByPage(1) 
#4 D:\wamp\www\Bucatarie\library\Zend\Paginator.php(1064): Zend_Paginator->getCurrentItems() 
#5 D:\wamp\www\Bucatarie\library\Zend\Paginator.php(816): Zend_Paginator->_createPages('Sliding') 
#6 D:\wamp\www\Bucatarie\library\Zend\View\Helper\PaginationControl.php(119): Zend_Paginator->getPages('Sliding') 
#7 [internal function]: Zend_View_Helper_PaginationControl->paginationControl(Object(Zend_Paginator), 'Sliding', 'partials/pagina...') 
#8 D:\wamp\www\Bucatarie\library\Zend\View\Abstract.php(342): call_user_func_array(Array, Array) 
#9 [internal function]: Zend_View_Abstract->__call('paginationContr...', Array) 
#10 D:\wamp\www\Bucatarie\application\modules\admin\views\scripts\menu-profiles\profile-products.phtml(44): Zend_View->paginationControl(Object(Zend_Paginator), 'Sliding', 'partials/pagina...') 
#11 D:\wamp\www\Bucatarie\library\Zend\View.php(108): include('D:\wamp\www\Buc...') 
#12 D:\wamp\www\Bucatarie\library\Zend\View\Abstract.php(880): Zend_View->_run('D:/wamp/www/Buc...') 
#13 D:\wamp\www\Bucatarie\library\Zend\Controller\Action\Helper\ViewRenderer.php(897): Zend_View_Abstract->render('menu-profiles/p...') 
#14 D:\wamp\www\Bucatarie\library\Zend\Controller\Action\Helper\ViewRenderer.php(918): Zend_Controller_Action_Helper_ViewRenderer->renderScript('menu-profiles/p...', NULL) 
#15 D:\wamp\www\Bucatarie\library\Zend\Controller\Action\Helper\ViewRenderer.php(957): Zend_Controller_Action_Helper_ViewRenderer->render() 
#16 D:\wamp\www\Bucatarie\library\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() 
#17 D:\wamp\www\Bucatarie\library\Zend\Controller\Action.php(523): Zend_Controller_Action_HelperBroker->notifyPostDispatch() 
#18 D:\wamp\www\Bucatarie\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('profileProducts...') 
#19 D:\wamp\www\Bucatarie\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#20 D:\wamp\www\Bucatarie\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#21 D:\wamp\www\Bucatarie\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#22 D:\wamp\www\Bucatarie\public\index.php(26): Zend_Application->run() 
#23 {main} 

請指教。

+0

解決。我不得不使用$ adapter = new Zend_Paginator_Adapter_DbSelect($ select);而不是Zend_Paginator_Adapter_DbTableSelect – user253530 2010-08-31 04:17:06

+0

你能以一種能夠幫助他人的方式回答你自己的問題嗎?如果你這樣做,你可以選擇你的正確答案。這可能看起來很奇怪,但在這種情況下,最好刪除它。 – Will 2011-04-06 15:47:33

回答

2

你需要

$select = $this->select() 
         ->from(array('mpp' => 'menu_profiles_products'), array('NAME' => 'p.name', 'PRICE' => 'p.price*mp.added_value/100')) 
         ->join(array('p' => 'products'), 'p.id = mpp.product_id') 
         ->join(array('mp' => 'menu_profiles'), 'mp.id = mpp.profile_id') 
         ->where('mpp.profile_id = ?', $profileID); 

     $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); 
     return $adapter; 

或者如果你想使用Zend_Db_Select對象

$select = $this->getDefaultAdapter()->select() 
         ->from(array('mpp' => 'menu_profiles_products'), array('NAME' => 'p.name', 'PRICE' => 'p.price*mp.added_value/100')) 
         ->join(array('p' => 'products'), 'p.id = mpp.product_id') 
         ->join(array('mp' => 'menu_profiles'), 'mp.id = mpp.profile_id') 
         ->where('mpp.profile_id = ?', $profileID); 

     $adapter = new Zend_Paginator_Adapter_DbSelect($select); 
     return $adapter;