近来好像写有关CakePHP的文章比较多一些。搞的多了,难免会虚伪一下。这次刚写了一个小网站,顺便把新研究出来的有关CakePHP的知识共享一下。
这次程序方面没做太多的研究,主要考虑了一下网站优化,更确切的说是有关CakePHP Url地址的优化。
参考网站:中药材百科 – http://www.yaocai123.com
设置Url的文件为:app\config\routes.php
首页就不多说了,没有更改routes.php文件。
由栏目层说起:
中药材大全 - http://www.yaocai123.com/zhongyao/
中药种植 - http://www.yaocai123.com/zhongzhi/
中药处方 - http://www.yaocai123.com/chufang/
这三个地址,如果是用常规的CakePHP来写的话为三个Controller。分别为:zhongyao, zhongzhi, chufang。而现在这个项目只用到了一个Controller – MedicineController。在Routes.php中只需要要Controller和Action的名字隐藏掉,而貌似Controller的zhongyao只是MedicineController Index动作的参数而已。
MedicineController隐藏Controller、Action的方法(这句要写到最后):
Router::connect(‘/*’, array(‘controller’ => ‘medical’, ‘action’ => ‘index’));
然后说一下详细页:
鹿茸:http://www.yaocai123.com/view/lurong.html
简简单单的ViewController,只是隐藏掉了View的Action而已。
ViewController隐藏Action的方法:
Router::connect(‘/view/*’, array(‘controller’ => ‘view’, ‘action’ => ‘index’));
注:CakePHP版本1.2.5稳定版,转载请注明出自:phplamp博客站 – http://www.phplamp.org
PHPLAMP博客是专注于网站建设,搜索引擎研究,网站推广,网站优化的IT博客。