我的操作:在項目控制器NULL,而不是在Yii的DAO SQL INSERT值:bindValue
修訂行動。在項目/瀏覽ajaxLink名爲/行動#
public function actionAddInterest() {
$itm= Item::model()->find("`ItemId` = :itm", array(':itm' => $_GET['ItemId']));
$connection = yii::app()->db;
$sql1 = "INSERT INTO interest (UserId, ItemId)
VALUES(:usr, :itm)";
$command=$connection->createCommand($sql1);
$command->bindValue(":usr", Yii::app()->user->id);
$command->bindValue(":itm", $itm);
$command->execute();
}
我也試過傾銷變量,並通過螢火...返回NULL這個響應。所以有些東西不適用於$ _GET。
$itm= Item::model()->find("`ItemId` = :itm", array(':itm' => $_GET['ItemId']));
var_dump($itm);
die();
ORIGINAL
public function actionAddInterest() {
$model = new Item;
$connection = yii::app()->db;
$sql1 = "INSERT INTO interest (UserId, ItemId)
VALUES(:usr, :itm)";
$command=$connection->createCommand($sql1);
$command->bindValue(":usr", Yii::app()->user->id);
$command->bindValue(":itm", $model->ItemId);
// $command->bindValue(":itm", $model->ItemId, PDO::PARAM_INT); //also tried
$command->execute();
}
No值被從$model->ItemId
捕獲雖然,它返回一個NULL爲輸入。我在這裏錯過了什麼?
$ model如何訪問?傳入一個函數? –
Phill Pafford,編輯完整動作 – enfield