I have a form where I collect “job” data from to insert a new row into a DB table. Two fields are then used to recover a store id from a separate DB table. I’m just wondering if there’s a better way to do this kind of stuff. Here’s my bit of code, it just feels like there’s a better code for this:
Job controller:
if(isset($_POST['Job']))
{
$model->attributes=$_POST['Job'];
$model->store_id = $test = Job::getStoreId($model->account, $model->store_number);
if($model->save())
$this->redirect(array('view','id'=>$model->work_order));
}
Job model (query to retrieve the ID):
public static function getStoreId($account, $number)
{
$_id = Yii::app()->db->createCommand()
->select('id')
->from('store')
->where('account = :ui_account AND number = :ui_store_number', array(
':ui_account' => $account,
':ui_store_number' => $number
))->queryRow();
return $_id['id'];
}