Yii Framework Forum: Fetching a value from DB, cached - Yii Framework Forum

Jump to content

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

Fetching a value from DB, cached Rate Topic: -----

#1 User is offline   karim_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-January 10

Posted 15 January 2010 - 10:15 AM

Hi,

First of all let me say I Love Yii so far! Great job and i will definitly keep using this!

Now heres my problem:

I'm trying to validate a certain value in a function in one of my controllers.
the function performs a find, using the related model, and i fetch the values ID by querying its name.
I'll show you the code, it will make things easyer:
        private function fetchValueId($value){
            // Check database if value exists
            $model = DataBase::model()->find(
                    array(
                        'criteria' => array(
                            'select' => 'id',
                            'condition' => array('name' => $value),
                        ),
                    )
                    );
            echo $model->getAttribute('id');
        }


So this works fine when a valid value is submitted for example is have the value 'value1' which exists in the table, and has ID 1.
If i then put in the bogus value 'bogus' which doesnt exist in the table, the function returns 1, the attribute value of value1.

How can I overcome this? basically its cacheing somewhere or something, what i don't want in this function

Thanks in advance

P.S
I expected the result to be a false or something for the bogus value

This post has been edited by karim_: 15 January 2010 - 10:20 AM

0

#2 User is offline   karim_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-January 10

Posted 15 January 2010 - 10:44 AM

Hi, i already fixed it by using findByAttributes!

View Postkarim_, on 15 January 2010 - 10:15 AM, said:

Hi,

First of all let me say I Love Yii so far! Great job and i will definitly keep using this!

Now heres my problem:

I'm trying to validate a certain value in a function in one of my controllers.
the function performs a find, using the related model, and i fetch the values ID by querying its name.
I'll show you the code, it will make things easyer:
        private function fetchValueId($value){
            // Check database if value exists
            $model = DataBase::model()->find(
                    array(
                        'criteria' => array(
                            'select' => 'id',
                            'condition' => array('name' => $value),
                        ),
                    )
                    );
            echo $model->getAttribute('id');
        }


So this works fine when a valid value is submitted for example is have the value 'value1' which exists in the table, and has ID 1.
If i then put in the bogus value 'bogus' which doesnt exist in the table, the function returns 1, the attribute value of value1.

How can I overcome this? basically its cacheing somewhere or something, what i don't want in this function

Thanks in advance

P.S
I expected the result to be a false or something for the bogus value

0

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