![]() ![]() _helper->viewRenderer->setNoRender(true) ![]() In a typical ZF Application you would want to have your controllers extend Zend_Controller_Action, but in this case, we want them to extend Zend_Rest_Controller. I created a new folder named v1 under application/modulesto match my module setup, and moved the controllers & models folders into it. Note: this method will apply the REST route to ALL controllers If you are thinking of having a mix of REST controllers and regular Zend_Action_Controller you need to customize the route rules by initiating it in your Bootstrap.php instead.Īt this point, some clean-up of your application directory is probably a good idea … depending on your set-up of the REST route, you might want to delete the views folder if you apply REST to all your controllers. The REST route controls the URL scheme for our application, more on that later. Now we need to setup routing, ZF comes with its own REST route, so lets make sure all our controllers are setup to go through it by adding the following to our application.ini .type = Zend_Rest_Route You can skip this step if you don’t want Modules as part of your Application. ![]() (At this point you would want to re-organize your directory structure to accommodate modules.) This will enable Modules in your Application and setup the default module name as v1. You should also remove the following line from your application.ini file, otherwise ZF will complain about missing Module Bootstrap calsses. Configuration:Īs always, the first thing you’d wanna do is customize your application.ini file, here are the lines I’ve added: = "v1" I believe APIs should have maintainable revisions and as such I’ve used Zend Framework Modules to separate my API revisions, again, its easy enough to skip that and suit your own needs. My entire application is meant to be a REST API, I don’t have a mixed mode of web controllers and REST controllers, though it is easily possible to have both, with very little modifications to fit your needs once you read through the steps. I’m going to skip the initial project creation and assume you already know the basics, if not, spend some time on Google figuring it out first (I don’t recommend the ZF documentation since it’s more confusing than helpful!) The following describing how I built the REST implementation from scratch. I started an open-source project called: RESTful Zend Framework which is a custom Zend Framework Application built to act as a REST API. Update : This article is out of date, please refer to the GitHub repo for updated instructions, the same principles still apply, but with some changes and slight modifications. This is a re-post of an old blog post that gets a lot of traffic, and people have asked me about it since my move to Sbvtle. ![]()
0 Comments
Leave a Reply. |