Web Programming TutorialsLearn How to Create Static Pages in Zend Framework

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. <html>
    	     <h1> ZEND FRAMEWORK </h1>
                      Zend framework works on MVC architecture.
  4. Save this file in the static folder in the public folder.
  5. Write a custom route to handle the static pages as shown below:
  6. resources.router.routes.staticpage.route = /static/:filenm
    resources.router.routes.staticpage.defaults.controller =
    resources.router.routes.staticpage.defaults.action = display
  7. This static page custom route will take a url of the form /static/info. It will store info as a parameter named filenm.
  8. 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:
  9. class StaticcontController extends Zend_Controller_Action
    public function displayAction()
    $page = $this->getRequest()->getParam('filenm');
  10. 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.
  11. Here in the above code the parameter named filenm will take info.html as the page to be rendered.
  12. Now to view the output, we need to write the following URL in the address bar of the browser as shown below:
  13. 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.


Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article


More article

- Advertisement -Eduonix Blog