我正在使用 YII 框架
$job_status = Yii::app()->db->createCommand()
->select('count(*) as total_count, Image_status')
->from('AllDetail')
->where("JobID=:job_id",array(':job_id'=>$job_id))
->group('Image_status')
->queryAll();
$status_key = array();
$images = array();
foreach($job_status as $job){
$imgstate = array_push($status_key,CompClass::statusMaster($job['Image_status']));
$tot_img = array_push($images,$job['total_count']);
}
Status Master 引用了我的组件类中的一个函数
其中有
public static function statusMaster($status_code)
{
switch($status_code)
{
case 0:
$alias = 'QUEUE';
break;
case 1:
$alias = 'PROCESSING';
break;
case 2:
$alias = 'COMPLETED';
break;
}
return $alias;
}
这是我的看法
<strong>Queued: <?php echo $job_status['QUEUE']; ?></strong><br />
<strong>Processing: <?php echo $job_status['PROCESSING']; ?></strong><br />
<strong>Completed: <?php echo $job_status['COMPLETED']; ?></strong><br />
如果上面的脚本没有任何 status_code(即),则会引发错误
如果数据库中的图像有status_code 0 and 1
but not 2
我得到undefined index completed
。相反,它应该显示为0
.
我是否可以使用任何其他有效方法的异常处理