天天看點

phalcon遇到的那些坑

1.資料重複插入

資料被重複插入,一般是在index/index方法中進行資料庫insert操作,會發現一條資料被重複插了一次。

原因:浏覽器有時候會自動請求 /favicon.ico ,而你的網站并沒有這個檔案,恰好預設路由又無法比對這種帶有"點"的路徑,是以呢,就被當作無比對的路徑了,這時候就會進入defaultController/defaultAction了,相當于多請求了index/index,進而造成插入兩次資料。

解決:為路由服務添加 notFound 配置,例如:$router->notFound(array('controller'=>'httperr','action'=>'err404'));其中httperr和err404是自己建立的控制器和方法。這樣當路由比對不到路徑的時候,就會進入這個控制器,而不會進入預設控制器了,問題得以解決。

<!-- lang: php -->

$router->add('/',array(

  "controller"=>'index',

  "action"=>'index'

));

$router->notFound(array('controller'=>'httperr','action'=>'err404'));

2.大小寫問題