[英]Phalcon router sends the wrong parameters
我的Phalcon路由器有問題。 我在我的控制器中有一個動作,以太有一個日期參數。 因此,當我訪問網址時: http : //example.com/sl/slots/index/2017-06-27一切正常。 但是當我去: http : //example.com/sl/slots/index我收到以下錯誤:
DateTime :: __ construct():無法解析位置0(s)處的時間字符串(sl):在數據庫中找不到時區。
所以路由器實際上將開頭的“sl”作為參數。
我的這種網址的路由器設置如下:
$router->add(
"/{language:[a-z]{2}}/:controller/:action",
array(
"controller" => 2,
"action" => 3
)
);
順便說一句,它與索引相同: http : //example.com/sl/slots
哦,我的插槽索引操作如下所示:
public function indexAction($currentDate = false){ //code }
所以當我在沒有參數的情況下調用動作時,$ currentDate被設置為“sl”
感謝您的幫助
那么你需要在行動的第一個參數中添加語言。 然后它應該工作。
除了@Juri的答案之外......我更喜歡讓我的行動空洞或盡可能地保持苗條。 想象一下,如果你在路線中有3-4個參數,你最終會得到類似的東西:
public function indexAction($param1 = false, $param2 = false, $param3 = false....)
以下是我更喜歡處理Route參數的方法:
public function indexAction()
{
// All parameters
print_r($this->dispatcher->getParams());
// Accessing specific Named parameters
$this->dispatcher->getParam('id');
$this->dispatcher->getParam('language');
// Accessing specific Non-named parameters
$this->dispatcher->getParam(0);
$this->dispatcher->getParam(1);
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.