Kohana:没有一个时未定义的索引

Kohana:没有一个时未定义的索引

问题描述:

I'm using Kohana 3.1 and I'm getting a very strange error. The Kohana POST handler seems to think that there's an undefined index when there is not one.

Inside of a controller class:

$post = $this->request->post();
var_dump(isset($post['jid'])); //true
$jid = $post['jid']; //Undefined Index error.

If I actually use $post['jid'] it works fine, but it is annoying to not be able to assign it to a more convenient variable. Anyone have any idea what would cause this?

ErrorException [ Notice ]: Undefined index: jid
84       $jid = $post['jid'];

var_dump of $post:

array(4) { 
    ["jid"]   => string(1) "7" 
    ["topic"] => string(5) "Test1"
    ["entry"] => string(14) "CHECK ONE TWO" 
    ["enter"] => string(4) "POST" 
}

我正在使用Kohana 3.1而且我收到一个非常奇怪的错误。 Kohana POST处理程序似乎认为没有一个未定义的索引。 p>

控制器类内部: p>

  $  post = $ this-> request-> post(); 
var_dump(isset($ post ['jid']));  // true 
 $ jid = $ post ['jid'];  //未定义索引错误。
  code>  pre> 
 
 

如果我实际使用 $ post ['jid'] code>它可以正常工作,但它很烦人 无法将其分配给更方便的变量。 任何人都知道会导致这种情况的原因是什么? p>

  ErrorException [注意]:未定义的索引:jid 
84 $ jid = $ post ['jid']; 
  code  >  pre> 
 
 

$ post的var_dump: p>

  array(4){
 [“jid”] =>  string(1)“7”
 [“topic”] =>  string(5)“Test1”
 [“entry”] =>  string(14)“CHECK ONE TWO”
 [“enter”] =>  string(4)“POST”
} 
  code>  pre> 
  div>

Sometimes the problem is not as obvious as the error. The page was 302-redirecting (no post) to itself after completing the action where the post check is done. In fact, the initial post went through properly, but be careful about calling a method on $this when you mean to use another object (at least when $this is a controller). It's still unclear to me why Kohana didn't crash.

Altough I believe this is a PEBKAC, you can use $this->request->post('jid') as a getter for that variable.

Maybe you are just skipping the actual POST check?