Zend rest a routing controller to a specific controller

I am new to zend framework. I am trying to write a RESTful controller using Zend_Rest_Controller. I built one of a good tutorial http://www.techchorus.net/create-restful-applications-using-zend-framework It works great. So I added it to my existing zend application. I just wanted one controller to be RESTful, as well as the necessary changes to the bootstrap.

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

the server throws 500 internal server errors when I try to access the service using the URL http: //localhost/projectname/public/index.php/myservice , which should call index from the MyserviceController . The application has the following folder structure

 application/ configs/ application.ini controllers/ IndexContoller OneController TwoController Myservice forms layouts models modules/ app1module app2module app3module views Bootstrap.php 

this is application.ini for the project

 [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 phpSettings.date.timezone = "America/New_York" includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" includePaths.helpers = APPLICATION_PATH "/views/helpers" ;Module support resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.frontController.defaultModule = "default" resources.modules[] = "" resources.db.adapter = PDO_MYSQL resources.db.params.host = ******** resources.db.params.username = ********* resources.db.params.password = ********* resources.db.params.dbname = ********* [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1 

and this code for MyserviceController.php

 <?php class MyserviceController extends Zend_Rest_Controller { public function init() { parent::init(); $this->_helper->viewRenderer->setNoRender(true); } public function indexAction() { $this->getResponse()->setBody('Hello World'); $this->getResponse()->setHttpResponseCode(200); } public function getAction() { $this->getResponse()->setBody('Foo!'); $this->getResponse()->setHttpResponseCode(200); } public function postAction() { $this->getResponse()->setBody('resource created'); $this->getResponse()->setHttpResponseCode(200); } public function putAction() { $this->getResponse()->setBody('resource updated'); $this->getResponse()->setHttpResponseCode(200); } public function deleteAction() { $this->getResponse()->setBody('resource deleted'); $this->getResponse()->setHttpResponseCode(200); } } ?> 
+4
source share
1 answer

In "localhost / projectname / public / index.php / myservice" why are you using index.php , why not just / index / ?

The default URL structure of ZF is "http: // hostname / controller / action / parameters"

-one
source

Source: https://habr.com/ru/post/1398315/


All Articles