rest routes in zend rest controller

2019-08-30 10:32发布

My problem is that I have written rest controller just like e.g. in the link here.

My Bootstrap looks like this

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
    protected function _initDoctype()
       {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
       }
    protected function _initDatabase()
       {
        // get config from config/application.ini
         $config = $this->getOptions();
         $db = Zend_Db::factory($config['resources']['db']['adapter'],               $config['resources']['db']['params']);

        //set default adapter
         Zend_Db_Table::setDefaultAdapter($db);

       //save Db in registry for later use
       Zend_Registry::set("db", $db);

       error_reporting(E_ALL|E_STRICT);
       ini_set('display_errors', 'on');
       }
    protected function _initAutoload()
       {     

       $modeloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => '',
                     'basePath' => APPLICATION_PATH));

      $auth =Zend_Auth::getInstance();
      $acl =new Model_LibraryAcl;       


      $fc=Zend_Controller_Front::getInstance();
      $fc->registerPlugin(new Plugin_AccessCheck($acl,$auth));
      return $modeloader;
       }  
   public function _initGlobalsetting()
      {
       define('SITE_URL', "http://".$_SERVER['HTTP_HOST']);
      }
   protected function _initAutoloader()
      {
       $autoloader = Zend_Loader_Autoloader::getInstance();
       $autoloader->registerNamespace("Api"); // or Example_
      }
   public function _initfileUpload()
      {
       define('PUBLIC_PATH', realpath(dirname(__FILE__))); 
      }

    protected function _initRestRoute()
       {
        $this->bootstrap('frontController');
        $frontController = Zend_Controller_Front::getInstance();
        $restRoute = new Zend_Rest_Route($frontController, array() , array('controller' =>array('ApiController')));
        $frontController->getRouter()->addRoute('rest', $restRoute);

       }  

    }
?>

Even though i remove entry for _initRestRoute() from Bootstrap. It's working properly then what is the use of rest controller. Am implementing it right way?

link to my code: how to call restful zend controller usin curl in php?

0条回答
登录 后发表回答