Yii框架:检查用户是否填写了所需的配置文件字段

时间:2014-11-18 11:01:53

标签: php yii

我有一些需要的个人资料字段,但未在注册页面中询问。

如何在主题文件夹\ views \ layout \ tpl_navigation.php 中查看是否已完成其个人资料,以显示提醒(您必须按顺序填写个人资料到...... )如果他们没有?

2 个答案:

答案 0 :(得分:0)

尽管不清楚,但建议如下:

我假设你可以通过以下方式获得登录用户ID:

$uid=Yii::app()->user->id;

此外,用户的模型名为User

然后,在你的控制器中:

public function beforeAction($action) {
    //getting user id
    $uid=Yii::app()->user->id;
    //finding user 
    $user=User::model()->findByPk($uid);
    //checking if address or mobile is empty
    if(empty($user->address) || empty($user->mobile)){//and othe fields
        Yii::app()->user->setFlash('PROFILE_IS_NOT_COMPLETED',TRUE);
    }
    parent::beforeAction($action);
}

然后在你的模板中:

if (Yii::app()->user->hasFlash('PROFILE_IS_NOT_COMPLETED') && Yii::app()->user->getFlash('PROFILE_IS_NOT_COMPLETED',FALSE)===TRUE) {
        echo CHtml::tag('span', array('style' => 'color:red'), "Please complete your profile"); //Just an example!
        //you absolutely need customization here
    }

答案 1 :(得分:0)

解决了,很容易:

$profile = Yii::app()->getModule('user')->user()->profile;
$validate =  $profile->validate();

if(!$validate) 
    echo '<div class="alert alert-error">Complete your profile...</div>';