2011-05-26 65 views
4

我的問題似乎與On submit the form don't display its POST data和相關問題類似,但建議的解決方案不適用於我的項目,所以我目前不使用重定向。Zend Framework - 提交不包含發佈數據

我正在嘗試學習Zend Framework。我正在處理的當前項目遇到了從我的表單傳遞的$ _POST和$ _GET超全局變量返回空的問題。我一直致力於簡化問題以確定問題的起因,但​​我似乎碰到了一堵磚牆。似乎沒有POST數據在所有被髮送...

筆者認爲:

<form method="post" action="/character/addsubmit"> 
    <input type=hidden name='test' id='test' value='test'> 
    <input type='submit'> 
</form> 

我的控制器:

<?php 
    class CharacterController extends Zend_Controller_Action 
    { 
     public function addsubmitAction() 
     { 
      Zend_Debug::dump($this->getRequest()); 

      echo "<br/>\$_POST: <br/>"; 
      print_r($_POST); 
      echo "<br/>\$_GET: <br/>"; 
      print_r($_GET); 
      echo "<br/><br/>"; 

      if($this->_request->isPost()) { 
       echo "\$_POST Found<br/>"; 
      } 
      else { 
       echo "\$_POST Not Found <br/>"; 
      } 

      if ($this->_request->isGet()) { 
       echo "\$_GET Found<br/>"; 
      } 
      else { 
       echo "\$_GET Not Found<br/>"; 
      } 
     } 
    } 
?> 

導航到表單,然後提交(點擊提交按鈕),我收到以下輸出:

object(Zend_Controller_Request_Http)#8 (15) { 
    ["_paramSources:protected"] => array(2) { 
    [0] => string(4) "_GET" 
    [1] => string(5) "_POST" 
    } 
    ["_requestUri:protected"] => string(20) "/character/addsubmit" 
    ["_baseUrl:protected"] => string(0) "" 
    ["_basePath:protected"] => NULL 
    ["_pathInfo:protected"] => string(20) "/character/addsubmit" 
    ["_params:protected"] => array(3) { 
    ["controller"] => string(9) "character" 
    ["action"] => string(9) "addsubmit" 
    ["module"] => string(7) "default" 
    } 
    ["_rawBody:protected"] => NULL 
    ["_aliases:protected"] => array(0) { 
    } 
    ["_dispatched:protected"] => bool(true) 
    ["_module:protected"] => string(7) "default" 
    ["_moduleKey:protected"] => string(6) "module" 
    ["_controller:protected"] => string(9) "character" 
    ["_controllerKey:protected"] => string(10) "controller" 
    ["_action:protected"] => string(9) "addsubmit" 
    ["_actionKey:protected"] => string(6) "action" 
} 

$_POST: 
Array () 
$_GET: 
Array () 

$_POST Not Found 
$_GET Found 

有一件事真的讓我失望op是isGet函數返回true ..

有沒有人有更多的Zend知識有任何想法,爲什麼我有這麼多的麻煩提交表單與此框架?是否有一些配置可能會導致錯誤或可能設置錯誤?

注:我正在使用Zend_Form實際應用程序,以及使用更多的框架本身,但我試圖調試此問題已縮小它。如果您需要關於我的配置的更多信息,我將能夠提供。

謝謝!

編輯:

我的.htaccess文件的內容:

[因爲這是錯誤的文件我已經刪除了這些行, 我仍然在尋找正確的。]

+0

安置自己的'.htaccess'文件的內容(如果使用Apache) – Phil 2011-05-26 06:04:57

+0

你能提供真實生產這種形式Zend_Form類? – 2011-05-26 09:22:29

+0

@Phil我正在使用GoDaddy主機(是的,我知道,不是最好的,但它是我有的,我會看到我能爲你找到的東西 – VOIDHand 2011-05-26 12:50:30

回答

0

有你試過

$this->_request->getParams(); 
+0

是的,我有。不幸的是,它僅從上面的_request列表中返回「_params :: protected」結果中的部分,只有「controller」,「action」和「module」字段。感謝您的快速回應。 – VOIDHand 2011-05-26 12:54:54

2

此線程舊,但下面的提示可能會幫助其他讀者。我剛剛遇到過這個問題,並在這裏找到了解決辦法:

https://serverfault.com/questions/127674/mysteriously-empty-post-array

我剛剛建立了一個當地的LAMP開發環境,並通過phpMyAdmin的填充我的數據庫,改變了post_max_size指令php.ini允許上傳大型SQL轉儲。遺憾的是,我在INI文件中錯誤輸入1G作爲1GB。 PHP將其解釋爲1字節限制,這自然是我所有的POST提交超過,因此他們到達空陣列。

檢查服務器的錯誤日誌,類似下面:

[Sat Oct 01 17:08:07 2011] [error] [client 127.0.0.1] PHP Warning: Unknown: POST Content-Length of 63 bytes exceeds the limit of 1 bytes in Unknown on line 0, referer: http://localhost/[...]