【发布时间】:2014-01-09 15:41:50
【问题描述】:
我正在创建一个非常简单的表单来从用户那里收集数据并存储在数据库中,但是我收到了一个错误:
ErrorException [注意]:数组到字符串的转换 SYSPATH\classes\kohana\html.php
我之前在我的另一个表单中使用过此代码,我从来没有遇到任何问题,也许我遗漏了什么?
<div id="formWrapper">
<?php
{
echo form::open('', array('id'=>'newprefecture'));
echo form::label('NewPrefecture', 'prefecture:');
echo form::input('form[NewPrefecture]', array('class'=>'input', 'id'=>'NewPrefecture'));
echo form::submit('btnSubmit', 'Submit', array('id'=>'btnSubmit', 'class'=>'button'));
echo form::close();
}
?>
</div>
public function action_newprefecture(){
$this->template->content = View::factory('admin/main-menu');
$this->template->content->val = '';
$this->template->content->post = '';
if ($this->request->post('form')) {
$post = $this->request->post('form');
$stmt = DB::query(Database::INSERT, 'INSERT INTO `prefectures` (`prefecture`)
VALUES (:NewPrefecture)');
$stmt->param(':NewPrefecture', $post['NewPrefecture']);
try {
$stmt->execute();
$this->template->content->post = $post;
$this->template->content->thanks = true;
} catch (Exception $e) {
FB::error($e);
}
}
}
【问题讨论】:
-
错误应该指向代码中的特定行 - 是它?
-
1) 这不是一个错误,它是一个通知,它只是意味着您将一个数组传递给一个函数,该函数试图将该数组作为一个字符串
echo。 2) 正确缩进/格式化代码 3) 添加通知中的行号 4) 随时随地避免使用静态方法 -
第 66 行 - 返回 htmlspecialchars( (string) $value, ENT_QUOTES, Kohana::$charset, $double_encode);