Learn How to Create Static Pages in Zend Framework

0
2346
Learn How to Create Static Pages in Zend Framework

Learn How to Create Static Pages in Zend FrameworkWe 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.
  1. Create a folder named static in the public folder in the Zend framework folder.
  2. Now create an html file say info.html. the code written in the file is given below:
  3. Save this file in the static folder in the public folder.
  4. Write a custom route to handle the static pages as shown below:
  5. This static page custom route will take a url of the form /static/info. It will store info as a parameter named filenm.
  6. 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:
  7. 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.
  8. Here in the above code the parameter named filenm will take info.html as the page to be rendered.
  9. Now to view the output, we need to write the following URL in the address bar of the browser as shown below:
  10. http://localhost/ZFApp/public/static/info.html

Thus we learned to create static pages in the Zend framework in this Creating Static pages in Zend Framework tutorial.

LEAVE A REPLY

Please enter your comment!
Please enter your name here