Home  >  Article  >  Backend Development  >  How to implement static page display in Yii

How to implement static page display in Yii

WBOY
WBOYOriginal
2016-07-29 08:51:531054browse

The example in this article describes the method of displaying static pages in Yii. Share it with everyone for your reference, the details are as follows:

Use a CViewAction built in Yii to serve all these pages.

First, create a controller class such as DocController, covering the actions method

public function actions()
{
  return array(
    'page'=>array(
      'class'=>'CViewAction',
    ),
  );
}

According to the official guide, the above code declares an external action class CViewAction.

Then, generate the directory protected/views/doc/pages.

Finally, store a file called about.php in this directory with the content: "about this site". At this time, these pages will use the application's default layout file. Therefore this file only describes the content relevant to this page.

http://www.yourhost.com/index.php?r=doc/page&view=about

If there are many static pages, you can put them in a subdirectory. Suppose there is a static page in protected/views/doc/pages/help/contact.php:

http://www.yourhost.com/index.php?r=doc/page&view=help.contact

Of course, we can also customize CViewAction Behavior, check the API documentation to learn more about CViewAction

Readers who are interested in more Yii-related content can check out the special topics of this site: "Summary of Getting Started with Yii Framework and Common Techniques", "Summary of PHP Excellent Development Framework", "smarty" "Basic Tutorial for Getting Started with Templates", "Summary of PHP Date and Time Usage", "Introduction Tutorial on PHP Object-Oriented Programming", "Summary of PHP String Usage", "Introduction Tutorial for PHP+MySQL Database Operation" and "PHP Common Databases" Summary of operating skills》

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

The above introduces the method of displaying static pages in Yii, including the methods of yii. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn