【发布时间】:2014-03-15 18:11:33
【问题描述】:
我现在正在使用 Phalcon PHP 库,
当我在 GamesModel 的参数中使用 PDO 绑定时,我不再得到结果,有什么想法吗?
我在工作through this
查看:(json_output.phtml)
echo $output->active;
型号:
class GamesModel extends Phalcon\Mvc\Model
{
public function initialize()
{
$this->setSource("games");
}
/**
Returns the status of a game found by ID
@param $id The game ID
*/
public function getStatusById( $id )
{
$result = GamesModel::query()
->where("id = :id:")
->bind( array("id" => $id) )
->execute();
//$result = GamesModel::findFirst(3);
return $result;
}
}
控制器:
class GameController extends Phalcon\Mvc\Controller
{
private $gamesModel;
public function initialize()
{
$this->gamesModel = new GamesModel();
}
public function getStatusByIdAction( $id ){
$this->view->setVar("output", $this->gamesModel->getStatusById( $id ) );
$this->view->pick("layouts/json_output");
}
}
表格
../game/getStatusById/3 在我取消注释 findFirst() 时显示为 0
否则我会得到
注意:未定义的属性: Phalcon\Mvc\Model\Resultset\Simple::$active ..\json_output.phtml on 第 3 行
我错过了什么吗?
我已在连接中将字符集定义为 UTF8。
【问题讨论】:
-
GamesModel::findFirst(3) 和 GamesModel::findFirstById(3) 也在内部使用绑定参数
-
你是说findFirst()自动绑定参数?因为在示例页面中它建议您需要这样做以消除 SQL 注入的风险
-
是的,它会自动绑定参数,你可以在你的数据库连接中添加一个日志,你可以看到它是如何通过占位符传递参数的