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

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 database and implementing a 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. Name them about.php and contact.php.
  3. Now, you can try your pages by typing:

    http://example.com/index.php?r=site/page&view=contact

    Alternatively, you can type the following:

    http://example.com/site/page/view/about

    If you have configured clean URLs with path format.

How it works...

We are connecting 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 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 recipe named Using external actions in this chapter
主站蜘蛛池模板: 浏阳市| 甘德县| 宁陵县| 仪陇县| 武宁县| 呼伦贝尔市| 吴堡县| 大庆市| 临武县| 灯塔市| 理塘县| 井陉县| 西峡县| 大渡口区| 肥东县| 师宗县| 会东县| 锦屏县| 乌鲁木齐市| 乌兰察布市| 新蔡县| 珠海市| 富宁县| 治县。| 崇义县| 五大连池市| 开原市| 犍为县| 韶关市| 大洼县| 阜康市| 弋阳县| 南京市| 长春市| 龙门县| 青阳县| 康乐县| 九江县| 年辖:市辖区| 盈江县| 五原县|