zend框架选择连接错误getTable()

发布于 2024-09-17 00:29:32 字数 3979 浏览 4 评论 0原文

我正在尝试在我的模型中实现此方法:

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}  

请告知。

I am trying to implement this method in my model:

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;
    }
}

I get an error Unrecognized method 'getTable()'

Basically I'm trying to implement this SQL query:

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>

Stack trace dump from 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}  

Please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2024-09-24 00:30:00

你需要OR

$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;

You need

$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;

OR if you want use 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文