我有一个控制器,我在图像构造方法中使用它的结果作为图像的src,在这里它的代码:
static function getCamByClassIdForAdmin($id)
{
$connection=Yii::app()->db;
$command=$connection->createCommand("Select Cam1,Cam2 from crd_classes where id={$id}");
$camReader=$command->query();
$camList=$command->queryAll();
//I do such strange things to get result, because when I tried return $camList[0]['Cam1'] or to use indexes in constructor of image it says that it has undefined offset - 0 for some reason
$result="";
foreach ($camList as $cam)
{
foreach ($cam as $current => $currentValue)
{
if ($current=='Cam1')
{
$result=$currentValue;
}
}
}
$camId=$result;
return $result;
};
以下是我在图像构造函数中使用它的方法:
'value' => function($data, $row) {
return CHtml::image(
//LessonsController::getCamByClassId($data->Lesson_ID)[0]['Cam1'],
LessonsController::getCamByClassIdForAdmin($data->Lesson_ID),
"default image",
array('width'=>195, 'height'=>110)
);
}
所以它会返回结果,我希望如此。接下来我想在另一个查询中使用此查询的结果,所以我修改了这样的控制器代码。
static function getCamByClassIdForAdmin($id)
{
$connection=Yii::app()->db;
$command=$connection->createCommand("Select Cam1,Cam2 from crd_classes where id={$id}");
$camReader=$command->query();
$camList=$command->queryAll();
$result="";
foreach ($camList as $cam)
{
foreach ($cam as $current => $currentValue)
{
if ($current=='Cam1')
{
$result=$currentValue;
}
}
}
$camId=$result;
$connection1=Yii::app()->db;
$command1=$connection1->createCommand("Select cam from cam_names where id={$camId}");
$camReader1=$command1->query();
$camList1=$command1->queryAll();
return $result;
}
我得到例外:
The SQL statement executed was: Select cam from cam_names where id=
所以,$camId
似乎是空的,但事实并非如此。为了检查这一点,我在$camId=$result;
ob_start();
var_dump($camId);
$result=ob_get_clean();
但仍然选择语句就像它是空的。
你有什么建议为什么它会像这样表现?
的更新
试过这个:
$result=$connection->createCommand("Select Cam1 from crd_classes where id={$id}")->queryScalar();
$resultCam=$connection->createCommand("Select cam from cam_names where id={$result}")->queryScalar();
这减少了很多代码。但错误是一样的
The SQL statement executed was: Select cam from cam_names where id=
的 UPDATE1
我甚至试图将它们分成两种不同的方法。
static function getCamByClassIdForAdmin($id)
{
$connection=Yii::app()->db;
$result=$connection->createCommand("Select Cam1 from crd_classes where id={$id}")->queryScalar();
return $result;
}
static function getCamNameByIdForAdmin($id)
{
$connection=Yii::app()->db;
$result=$connection->createCommand("Select cam from cam_names where id={$id}")->queryScalar();
return $result;
}
奇怪的行为仍然存在:
return CHtml::image(
LessonsController::getCamByClassIdForAdmin($data->Lesson_ID),
"default image",
array('width'=>195, 'height'=>110)
);
返回cam的id 但 返回CHtml :: image( LessonsController :: getCamNameByIdForAdmin(LessonsController :: getCamByClassIdForAdmin($ DATA-> Lesson_ID)), "默认图片", 数组('宽度' => 195,'高度' => 110) );
说错误:执行的SQL语句是:从cam_names中选择cam,其中id =
我甚至试图将它们公开而不是静态。结果是一样的。
更新2
看起来$id
没有填充,但它是.Proof:
static function getCamNameByIdForAdmin($id)
{
ob_start();
var_dump($id);
$result=ob_get_clean();
/*$connection=Yii::app()->db;
$result=$connection->createCommand("Select cam from cam_names where id={$id}")->queryScalar();*/
return $result;
}
返回:
string(3) "741
UPDATE3
尝试debug_zval_dump
代替var_dump
我收到了
string(3) "741" refcount(3)
在我的src中,所以还有2个refs在某个地方没有功能。当我看到xdebug时,我可以告诉更多我希望。