php - Kohana:没有索引时未定义索引

标签 php kohana undefined-index

我正在使用 Kohana 3.1,但遇到了一个非常奇怪的错误。 Kohana POST 处理程序似乎认为存在 undefined index ,但实际上没有。

Controller 类内部:

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

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

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

$post 的 var_dump:

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

最佳答案

虽然我相信这是一个 PEBKAC,但您可以使用 $this->request->post('jid') 作为该变量的 getter。

也许你只是skipping the actual POST check

关于php - Kohana:没有索引时未定义索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6260207/

相关文章:

javascript - 如何在 javascript 上使用 PHP var? (PHP 代码)

php - 如何使用Kohana的$this->request->param获取请求变量

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

javascript - 正在加载自定义论坛帖子 : php echo vs. javascript.createElement

php - 通过API获取flickr私有(private)图像

PHP 计时器每秒输出到 HTML div 中

php - url::redirect 在 kohana 3.1 中

Kohana 3 - 我可以在运行时更改配置文件的设置吗?

php - $_POST 未定义索引

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP