1.最近學習yaf 看到手冊上說默認路由方式,一系列安裝后,輸入網(wǎng)址顯示Hello World! I am Stranger這是正常的!
2.但是我在controlers下面的Index.php文件里面新建public function testAction方法,路由訪問http://sitename/Index/Index/test,始終訪問的是indexAction方法的內(nèi)容!
3.求大神指導!(另:如果我想把控制器分類,例如目錄是controllers/son/son.php,這個文件中的控制器繼承controllers/father.php這種目錄格式我應該怎么設(shè)置路由?)
4.下面附上目錄和各種配置!
Nginx 配置
location / {
try_files $uri $uri/ /index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
#手冊配置 并不管用
# if (!-e $request_filename) {
# rewrite ^/(.*) /index.php/$1 last;
# }
}
Index控制器
<?php
/**
* @name IndexController
* @author root
* @desc 默認控制器
* @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
*/
class IndexController extends Yaf_Controller_Abstract {
/**
* 默認動作
* Yaf支持直接把Yaf_Request_Abstract::getParam()得到的同名參數(shù)作為Action的形參
* 對于如下的例子, 當訪問http://yourhost/demo/index/index/index/name/root 的時候, 你就會發(fā)現(xiàn)不同
*/
public function indexAction($name = "Stranger") {
//1. fetch query
$get = $this->getRequest()->getQuery("get", "default value");
//2. fetch model
$model = new SampleModel();
//3. assign
$this->getView()->assign("content", $model->selectSample());
$this->getView()->assign("name", $name);
//4. render by Yaf, 如果這里返回FALSE, Yaf將不會調(diào)用自動視圖引擎Render模板
return TRUE;
}
public function testAction()
{
echo "this is a test of router";
}
}
求各位大佬答疑解惑!
- 3 回答
- 0 關(guān)注
- 983 瀏覽
添加回答
舉報
0/150
提交
取消