Zend framework 为什么我的模型函数在ZEND中不起作用?

Zend framework 为什么我的模型函数在ZEND中不起作用?,zend-framework,model,controller,Zend Framework,Model,Controller,我想知道我的代码有什么问题: 这是我的控制器的功能: public function testareAction(){ // $this->getResponse()->setHeader('Content-Type', 'application/json'); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRende

我想知道我的代码有什么问题: 这是我的控制器的功能:

public function testareAction(){ 
    // $this->getResponse()->setHeader('Content-Type', 'application/json');
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    //$myarray =  $_POST['data_post'];
    //$product_ids = $_POST['product_ids'];
    //$type = 1;
    $model = new Application_Model_Order(); 
    echo $model -> saveOrderNames();
}
public function indexAction()
    {
        if (!($locationUrl = $this->_getParam('locationUrl'))) {
            throw new \Zend_Controller_Action_Exception('Location URL was not provided.', 404);
        }        

        $this->maiDivClass = "block clear step1";

        // get Location row
        $mapper = new DbTable\Location();
        $sql = $mapper->select()->where('url = ?', $locationUrl);

        if (!($this->view->location = $mapper->fetchRowActive($sql))) {
            throw new \Zend_Controller_Action_Exception('Location not found', 404);
        }

        // set active markup for location menu
        $this->_helper->layout()->locationMainMenuUrl = $this->view->location->url;

        // SEO
        $this->setSeo(
            $this->view->location->meta_title, 
            $this->view->location->meta_description, 
            $this->view->location->meta_keywords
        );

        // get day from param
        $dayName = $this->_getParam('day', Cronos::getCurrentDayName());

        $this->view->dayNo = Cronos::getWeekDayNumber($dayName);
        if ($this->view->dayNo === false) {
            throw new \Zend_Controller_Action_Exception('Invalid weekday provided.', 404);
        }

        $this->view->selectedDate = Cronos::getDateWithOffset($this->view->dayNo); // get date offset
        $this->view->categMapper  = new DbTable\Categories();

        $appCfg = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
        $this->view->s3 = "http://".$appCfg->custom->s3->bucket;
        $imgMapper = new Application_Model_Mapper_Images();
        $this->view->imgs = $imgMapper->fetchAllByLocationId($this->view->location->id);


        /**
         * Show products only for allowed admin emails. Testing only.
         * Admin must be logged in to see products, while the test is on.
         * 
         * To disable, change custom.test.isEnabled flag in app.ini.
         */
        $testCfg = Zend_Registry::get('Zend_Config')->custom->test->toArray();
        $isEnabled = (bool) $testCfg['isEnabled'];

        // test is enabled?
        if ($isEnabled) {
            $email = false; 
            $auth  = Zend_Auth::getInstance();
            // grab email, if logged in
            if ($auth->hasIdentity()) { $email = $auth->getIdentity()->email; }

            // has email? check it against config, else don't show products
            $showProducts = ($email) ? in_array($email, (array) $testCfg['email']) : false;

        // test is disabled: always show products
        } else {
            $showProducts = true;
        }

        if ($showProducts) {

            // get categories & products for this date and location
            $prodService = new \Application\Service\Products();
            $this->view->categsWithProds = $prodService->getProducts($this->view->location->id, $this->view->selectedDate); 

            //check days of the week with products
            $week = array();
            $currentDay = Cronos::getWeekDayNumberByDate();
            if($this->view->location->erp_name != "city lbox") {
                for($day=$currentDay;$day<7;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;

                }
                //we need to go to sunday and next week
                for($day=0;$day<$currentDay;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;
                } 
            } else {
                for($day = $currentDay; $day<7;$day++) {
                    $week[] = $day;
                }
                for($day = 0; $day<$currentDay; $day++) {
                    $week[] = $day;
                }
            }

            $this->view->week = $week;
            $specialMenuRows = $this->view->location->getSpecialMenus(new Zend_Date());
            $this->view->specialMenus = $this->view->partial('_partials/specialMenu.phtml', array('specialMenus' => $specialMenuRows));

            $this->view->categsWithProdsALaCarte =  $prodService->getProducts($this->view->location->id, $this->view->selectedDate, 1);

        // no xml; show "Download PDF"
        } else {
            $this->setPdfLink();
            $this->renderScript('location/no_xml.phtml');
        }
    }
public function testareAction(){ 
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        echo "1tralala";
        $model = new Application_Model_OrderNames(); 
        echo "2<hr>";
        $model -> saveOrderNames();

}
这是我模型中的功能:

public function saveOrderNames(){
    return 1;
}
为什么我不能在浏览器中得到结果1? 我是一个新手,所以请给我好的说明

thx:D 这是来自控制器的索引:

public function testareAction(){ 
    // $this->getResponse()->setHeader('Content-Type', 'application/json');
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    //$myarray =  $_POST['data_post'];
    //$product_ids = $_POST['product_ids'];
    //$type = 1;
    $model = new Application_Model_Order(); 
    echo $model -> saveOrderNames();
}
public function indexAction()
    {
        if (!($locationUrl = $this->_getParam('locationUrl'))) {
            throw new \Zend_Controller_Action_Exception('Location URL was not provided.', 404);
        }        

        $this->maiDivClass = "block clear step1";

        // get Location row
        $mapper = new DbTable\Location();
        $sql = $mapper->select()->where('url = ?', $locationUrl);

        if (!($this->view->location = $mapper->fetchRowActive($sql))) {
            throw new \Zend_Controller_Action_Exception('Location not found', 404);
        }

        // set active markup for location menu
        $this->_helper->layout()->locationMainMenuUrl = $this->view->location->url;

        // SEO
        $this->setSeo(
            $this->view->location->meta_title, 
            $this->view->location->meta_description, 
            $this->view->location->meta_keywords
        );

        // get day from param
        $dayName = $this->_getParam('day', Cronos::getCurrentDayName());

        $this->view->dayNo = Cronos::getWeekDayNumber($dayName);
        if ($this->view->dayNo === false) {
            throw new \Zend_Controller_Action_Exception('Invalid weekday provided.', 404);
        }

        $this->view->selectedDate = Cronos::getDateWithOffset($this->view->dayNo); // get date offset
        $this->view->categMapper  = new DbTable\Categories();

        $appCfg = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
        $this->view->s3 = "http://".$appCfg->custom->s3->bucket;
        $imgMapper = new Application_Model_Mapper_Images();
        $this->view->imgs = $imgMapper->fetchAllByLocationId($this->view->location->id);


        /**
         * Show products only for allowed admin emails. Testing only.
         * Admin must be logged in to see products, while the test is on.
         * 
         * To disable, change custom.test.isEnabled flag in app.ini.
         */
        $testCfg = Zend_Registry::get('Zend_Config')->custom->test->toArray();
        $isEnabled = (bool) $testCfg['isEnabled'];

        // test is enabled?
        if ($isEnabled) {
            $email = false; 
            $auth  = Zend_Auth::getInstance();
            // grab email, if logged in
            if ($auth->hasIdentity()) { $email = $auth->getIdentity()->email; }

            // has email? check it against config, else don't show products
            $showProducts = ($email) ? in_array($email, (array) $testCfg['email']) : false;

        // test is disabled: always show products
        } else {
            $showProducts = true;
        }

        if ($showProducts) {

            // get categories & products for this date and location
            $prodService = new \Application\Service\Products();
            $this->view->categsWithProds = $prodService->getProducts($this->view->location->id, $this->view->selectedDate); 

            //check days of the week with products
            $week = array();
            $currentDay = Cronos::getWeekDayNumberByDate();
            if($this->view->location->erp_name != "city lbox") {
                for($day=$currentDay;$day<7;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;

                }
                //we need to go to sunday and next week
                for($day=0;$day<$currentDay;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;
                } 
            } else {
                for($day = $currentDay; $day<7;$day++) {
                    $week[] = $day;
                }
                for($day = 0; $day<$currentDay; $day++) {
                    $week[] = $day;
                }
            }

            $this->view->week = $week;
            $specialMenuRows = $this->view->location->getSpecialMenus(new Zend_Date());
            $this->view->specialMenus = $this->view->partial('_partials/specialMenu.phtml', array('specialMenus' => $specialMenuRows));

            $this->view->categsWithProdsALaCarte =  $prodService->getProducts($this->view->location->id, $this->view->selectedDate, 1);

        // no xml; show "Download PDF"
        } else {
            $this->setPdfLink();
            $this->renderScript('location/no_xml.phtml');
        }
    }
public function testareAction(){ 
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        echo "1tralala";
        $model = new Application_Model_OrderNames(); 
        echo "2<hr>";
        $model -> saveOrderNames();

}
好的,我在models文件夹中创建了这个文件:OrderNames.php 这就是我的模型所包含的内容:

<?php
    class OrderNames {

        public function saveOrderNames(){
                 return 1;
                } 
    }   
?> 
这是控制器的功能:

public function testareAction(){ 
    // $this->getResponse()->setHeader('Content-Type', 'application/json');
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    //$myarray =  $_POST['data_post'];
    //$product_ids = $_POST['product_ids'];
    //$type = 1;
    $model = new Application_Model_Order(); 
    echo $model -> saveOrderNames();
}
public function indexAction()
    {
        if (!($locationUrl = $this->_getParam('locationUrl'))) {
            throw new \Zend_Controller_Action_Exception('Location URL was not provided.', 404);
        }        

        $this->maiDivClass = "block clear step1";

        // get Location row
        $mapper = new DbTable\Location();
        $sql = $mapper->select()->where('url = ?', $locationUrl);

        if (!($this->view->location = $mapper->fetchRowActive($sql))) {
            throw new \Zend_Controller_Action_Exception('Location not found', 404);
        }

        // set active markup for location menu
        $this->_helper->layout()->locationMainMenuUrl = $this->view->location->url;

        // SEO
        $this->setSeo(
            $this->view->location->meta_title, 
            $this->view->location->meta_description, 
            $this->view->location->meta_keywords
        );

        // get day from param
        $dayName = $this->_getParam('day', Cronos::getCurrentDayName());

        $this->view->dayNo = Cronos::getWeekDayNumber($dayName);
        if ($this->view->dayNo === false) {
            throw new \Zend_Controller_Action_Exception('Invalid weekday provided.', 404);
        }

        $this->view->selectedDate = Cronos::getDateWithOffset($this->view->dayNo); // get date offset
        $this->view->categMapper  = new DbTable\Categories();

        $appCfg = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
        $this->view->s3 = "http://".$appCfg->custom->s3->bucket;
        $imgMapper = new Application_Model_Mapper_Images();
        $this->view->imgs = $imgMapper->fetchAllByLocationId($this->view->location->id);


        /**
         * Show products only for allowed admin emails. Testing only.
         * Admin must be logged in to see products, while the test is on.
         * 
         * To disable, change custom.test.isEnabled flag in app.ini.
         */
        $testCfg = Zend_Registry::get('Zend_Config')->custom->test->toArray();
        $isEnabled = (bool) $testCfg['isEnabled'];

        // test is enabled?
        if ($isEnabled) {
            $email = false; 
            $auth  = Zend_Auth::getInstance();
            // grab email, if logged in
            if ($auth->hasIdentity()) { $email = $auth->getIdentity()->email; }

            // has email? check it against config, else don't show products
            $showProducts = ($email) ? in_array($email, (array) $testCfg['email']) : false;

        // test is disabled: always show products
        } else {
            $showProducts = true;
        }

        if ($showProducts) {

            // get categories & products for this date and location
            $prodService = new \Application\Service\Products();
            $this->view->categsWithProds = $prodService->getProducts($this->view->location->id, $this->view->selectedDate); 

            //check days of the week with products
            $week = array();
            $currentDay = Cronos::getWeekDayNumberByDate();
            if($this->view->location->erp_name != "city lbox") {
                for($day=$currentDay;$day<7;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;

                }
                //we need to go to sunday and next week
                for($day=0;$day<$currentDay;$day++)
                {
                    $selectedDate = Cronos::getDateWithOffset($day);
                    $categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
                    if(count($categswithprod))
                        $week[] = $day;
                } 
            } else {
                for($day = $currentDay; $day<7;$day++) {
                    $week[] = $day;
                }
                for($day = 0; $day<$currentDay; $day++) {
                    $week[] = $day;
                }
            }

            $this->view->week = $week;
            $specialMenuRows = $this->view->location->getSpecialMenus(new Zend_Date());
            $this->view->specialMenus = $this->view->partial('_partials/specialMenu.phtml', array('specialMenus' => $specialMenuRows));

            $this->view->categsWithProdsALaCarte =  $prodService->getProducts($this->view->location->id, $this->view->selectedDate, 1);

        // no xml; show "Download PDF"
        } else {
            $this->setPdfLink();
            $this->renderScript('location/no_xml.phtml');
        }
    }
public function testareAction(){ 
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        echo "1tralala";
        $model = new Application_Model_OrderNames(); 
        echo "2<hr>";
        $model -> saveOrderNames();

}
为什么字符串2tralala没有出现

您调用:$model=newapplication\u model\u ordername; php文件的名称是OrderNames.php 这个班是

class OrderNames {

    public function saveOrderNames(){
             return 1;
            } 
}   
因此,请尝试替换类的名称:

class Application_Model_OrderNames {...

采取有效的措施,粘贴代码,并将var_转储到debbug。也许是你的行动要求不好,也许是你的模型没有放在正确的目录中。您还应该在post变量中添加isset如果我使用var_dump$model->saveordername,它不会显示任何内容;是空的吗?如果是,尝试替换$model=新应用程序\模型\订单;echo$model->saveordername;由回声'福';它也是空的,在$model=newapplication\u model\u Order之后显示的所有内容;是否将类名替换为OrderNamesTest,并将TestReaction中的代码替换为:$model=new Application\u model\u OrderNamesTest;。正如您所说,文件名仍然是OrderNames.php。我没有得到回音字符串,其他选项?没有,如果你想要一个foo模型,你必须在application/models中有一个foo.php。在Foo.php中,类必须是class Application\u Model\u Foo{…},对Foo类的调用是new Application\u Model\u Foo{;