2016-09-23 137 views
0

我使用cakephp 3.3.2版本和5.6 php版本。CakePHP 3:給403禁止錯誤放

我的編輯動作的樣子

public function edit($id = null) { 
     $country = $this->Countries->get($id, [ 
       'contain' => [] 
      ]); 
     if ($this->request->is(['patch', 'post', 'put'])) { 
      $country = $this->Countries->patchEntity($country, $this->request->data); 
      if ($this->Countries->save($country)) { 
       $this->Flash->success(__('The country has been saved.')); 

       return $this->redirect(['action' => 'index']); 
      } else { 
       $this->Flash->error(__('The country could not be saved. Please, try again.')); 
      } 
     } 
     $this->set(compact('country')); 
     $this->set('_serialize', ['country']); 
    } 

這段代碼在本地主機工作正常,但在我的真實主機(使用共享主辦),它給了我403紫禁城的錯誤,當我準備做一些修改。然後我用郵遞員來檢查。然後我看到它對於獲取和發佈工作正常,但給予403禁止錯誤。在php或cakephp中有沒有額外的設置來解決這個問題?

回答

1

你說的它的工作在本地主機上,因此可能是服務器的問題.. 檢查此批答案 - Why does my web server software disallow PUT and DELETE requests?答案

+0

我使用的份額託管here.So它可能需要改變的.htaccess,但不知道如何在cakephp htaccess中添加此設置。 –

+0

我是比較新的cakephp ..你可以嘗試在htaccess的限制代碼,並檢查是否有幫助?據我所知,限制條件將被限制在包含htaccess文件的文件夾,所以你可能想嘗試在基礎文件夾以及src .. –

+0

我拒絕放置方法並應用所有形式的post定義post方法,然後我的問題得到解決。爲了安全起見,可能有些服務器不接受put方法。我接受你的答案,因爲它給了我一個解決這個問題的方向。 –