我使用CakePHP 2.2.0,我需要創建一個路由得到這樣的頁面:如何路由與擴展到特定的控制器的動作的CakePHP請求2.2.0
http://www.example.com/users/mypage.php
繼CakePHP的文件,我已經找到了這個網頁:http://book.cakephp.org/2.0/en/development/routing.html#file-extensions
在那裏我閱讀,我必須使用:
Router::parseExtensions('php');
我已經加入我的routes.php文件文件這一行(路線以上),比我添加了這條路線:
Router::connect('/users/mypage.php', array('controller' => 'users', 'action' => 'mypage'));
所以,在UsersController裏面我加了這個動作。
遺憾的是,只有送到www.example.com/users/mypage
工作良好(我的空間動作被調用)的要求,如果我嘗試www.example.com/users/mypage.php
我得到404未找到錯誤。
我真的不明白其中的道理,正如文件說:
這將告訴路由器,以消除任何匹配的文件擴展名,並 然後解析剩下。
所以,這正是我需要的,我必須解釋(僅此動作)的我的空間行動被稱爲當用戶數字/users/mypage.php(擴展)。
我沒有添加任何東西。 AppController是默認的,我的UsersController只有mypage()方法。
我不知道,如果NGINX的問題,我下面寫的域的配置:
server {
listen 80;
server_name www.example.com;
root /home/users/example.com/www/app/webroot/;
access_log /home/users/example.com/log/access.log;
error_log /home/users/example.com/log/error.log;
location/{
index index.php index.html;
try_files $uri $uri/ /index.php?$uri&$args;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我覺得這個問題是清楚的,如何將請求路由到如果請求特定的控制器的動作有擴展名嗎?
我需要:
www.example.com/users/mypage.php ==> to UsersController mypage()
謝謝你,但是,我嘗試添加.PHP的連接(和刪除parseExtensions()),並做反之亦然,我總是得到404沒有找到,所以你告訴我,NGINX應該是問題...你有什麼建議?我在那個盒子裏重複try_files? – Dail 2012-07-17 21:01:09