Search code examples
phpyiiyii1.x

Get the ID from the session public function search () in Yii1


public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;
    $criteria->addCondition('id=1');

    $criteria->compare('id',$this->id);
    $criteria->compare('login',$this->login,true);
    $criteria->compare('name',$this->name,true);
    $criteria->compare('password',$this->password,true);
    $criteria->compare('random_pass',$this->random_pass,true);
    $criteria->compare('default_number_of_devices',$this->default_number_of_devices);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
         'sort'=>array('defaultOrder'=>'name ASC',)


    ));
}

I use ID 1 like $criteria->addCondition('id=1'), it's not automatic just display record with id=1, how can I get automatic ID from user season login.


Solution

  • public function search()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.
    
        $criteria=new CDbCriteria;
        $sas= Yii::app()->user->id;
        $criteria->addCondition("id=$sas");
        $criteria->compare('id',$this->id);
        $criteria->compare('login',$this->login,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('password',$this->password,true);
        $criteria->compare('random_pass',$this->random_pass,true);
        $criteria->compare('default_number_of_devices',$this->default_number_of_devices);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
             'sort'=>array('defaultOrder'=>'name ASC',)
    
    
        ));
    }
    

    desc id like this $sas= Yii::app()->user->id; i think it run