Yii Framework Forum: Getting An Id (Query Builder) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Getting An Id (Query Builder) Rate Topic: -----

#1 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 11 February 2013 - 08:17 PM

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:
            $model->store_id = $test = Job::getStoreId($model->account, $model->store_number);

Job model (query to retrieve the ID):
    public static function getStoreId($account, $number)
        $_id = Yii::app()->db->createCommand()
                ->where('account = :ui_account AND number = :ui_store_number', array(
                    ':ui_account' => $account,
                    ':ui_store_number'  => $number
        return $_id['id'];


#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,382
  • Joined: 21-February 11
  • Location:Greece

Posted 23 February 2013 - 04:45 PM

Hi my friend

May you can do it by Relational Active Record but is depended by the complication of your Ar schema

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users