We have completed learning about controllers in Zend Framework in our previous tutorial, today in this tutorial we will learn how to create static pages in Zend Framework.
- Static pages are the pages used to display something constant on the web. Once created, they can be used any number of times in the website to display. Similar to other MVC frameworks, we can make folders to store these pages.
- You need to create a subfolder in the public directory and store your static page file in this subfolder.
- The default .htaccess file is already setup to serve any physical file that is web accessible.
- This method of storing pages in a subfolder imposes minimum overhead.
- Let us follow the steps and learn to create static pages in Zend framework.
- Create a folder named static in the public folder in the Zend framework folder.
- Now create an html file say info.html. the code written in the file is given below:
- Save this file in the static folder in the public folder.
- Write a custom route to handle the static pages as shown below:
- This static page custom route will take a url of the form /static/info. It will store info as a parameter named filenm.
- Now after this we need to write the controller to allow the file to display on the web. The controller file code is given below:
- Here we have a controller named staticcont which extends Zend_Controller_Action class. It has a method named displayAction which on execution renders the static page.
- Here in the above code the parameter named filenm will take info.html as the page to be rendered.
- Now to view the output, we need to write the following URL in the address bar of the browser as shown below:
<h1> ZEND FRAMEWORK </h1>
Zend framework works on MVC architecture.
resources.router.routes.staticpage.route = /static/:filenm
resources.router.routes.staticpage.defaults.action = display
class StaticcontController extends Zend_Controller_Action
public function displayAction()
$page = $this->getRequest()->getParam('filenm');
Thus we learned to create static pages in the Zend framework in this Creating Static pages in Zend Framework tutorial.