官术网_书友最值得收藏!

Displaying static pages with CViewAction

If you have a few static pages and aren't going to change them very frequently, then it's not worth querying the database and implementing page management for them.

Getting ready

Set up a new application using yiic webapp.

How to do it...

  1. We just need to connect CViewAction to our controller.
    class SiteController extends CController
    {
       function actions()
       {
          return array(
             'page'=>array(
                'class'=>'CViewAction',
            ),
          );
       }
    }
  2. Now, put your pages into protected/views/site/pages, and name them about.php and contact.php.
  3. Now, you can try your pages by typing in the URL http://example.com/index.php?r=site/page&view=contact.
  4. Alternatively, you can type in the URL http://example.com/site/page/view/about, if you have configured clean URLs with a path format.

How it works...

We connect the external action named CViewAction that simply tries to find a view named the same as the $_GET parameter supplied. If it is there, it displays it. If not, then it will give you a 404 not found page.

There's more...

There are some useful CViewAction parameters we can use. These are listed in the following table:

Further reading

For further information, refer to the following URL:

http://www.yiiframework.com/doc/api/CViewAction

See also

  • The Using external actions recipe
主站蜘蛛池模板: 托克逊县| 临泉县| 河间市| 洪雅县| 萨嘎县| 澎湖县| 涞水县| 酉阳| 扎兰屯市| 彝良县| 吴旗县| 福安市| 连南| 东兰县| 杨浦区| 石景山区| 新乐市| 隆昌县| 丰镇市| 格尔木市| 永新县| 辽源市| 连南| 吉安县| 潞西市| 彰武县| 抚宁县| 婺源县| 宜州市| 南涧| 崇阳县| 天水市| 兴化市| 金湖县| 河池市| 江永县| 汉沽区| 东光县| 高阳县| 环江| 扬中市|