dongpo4197 2018-10-11 23:48
浏览 150
已采纳

从Yii1中的会话公共函数search()获取ID

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.

  • 写回答

2条回答 默认 最新

  • duanhan5388 2018-10-12 00:39
    关注
    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部