我在yii2前端用户模型中定义了一些值,我的模型名称是' PhCabinetUser' 以下是我的模型中的代码。
class PhCabinetUser extends \yii\db\ActiveRecord
{
public $has_liveaccount;
public $email_verification;
public $account_deposited;
public $document_uploaded;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'ph_cabinet_user';
}
现在,当我尝试在我的控制器中获取$ email_verification时,它返回空值。
以下是我的控制器的代码。
$model = PhCabinetUser::find()->all();
$row = array();
foreach($model as $obj) {
echo $obj['email_verification'];
echo $obj->email_verification;
}
然而,当我打印$ obj数组时,它显示了email_verification的值 以下是我的print_r($ obj)结果。
crm\models\PhCabinetUser Object ( [has_liveaccount] => [email_verification] => [account_deposited] => [document_uploaded] => [_attributes:yii\db\BaseActiveRecord:private] => Array ( [id] => 29 [company_id] => 1 [first_name] => Super [last_name] => Man [username] => ksdwpfr3.a4q@20email.eu [email] => ksdwpfr3.a4q@20email.eu [registration_email_token] => PXwTu8KULal2_So5U3wVllxfKg1X-Dzh_1468296370 [country] => 2 [country_code] => +355 [phone] => 1234567890 [dob] => [gender] => male [address1] => [address2] => [city] => [state] => [zipcode] => [source] => Website [owner] => 1 [lead_manager] => [has_liveaccount] => 0
[email_verification] => 1
[account_deposited] => 0
[document_uploaded] => 0
[lead_status] => 1
[status] => 10
[created_at] => 1468296369 [updated_at] => 1468296580 )
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array (
[id] => 29
[company_id] => 1
[first_name] => Super
[last_name] => Man
[username] => ksdwpfr3.a4q@20email.eu
[auth_key] => Nc-GABmcqJIpib22L5cuwgBaOKqRvbiQ
[password_hash] => $2y$13$ZHB6IF51LODVqAEwI2zRkuIWbgEZ165acvpIeiVm2SZBFA1kzpp4S
[password_reset_token] =>
[email] => ksdwpfr3.a4q@20email.eu
[registration_email_token] => PXwTu8KULal2_So5U3wVllxfKg1X-Dzh_1468296370
[country] => 2
[country_code] => +355
[phone] => 1234567890
[dob] =>
[gender] => male
[address1] =>
[address2] =>
[city] =>
[state] =>
[zipcode] =>
[source] => Website
[owner] => 1
[lead_manager] =>
[has_liveaccount] => 0
[email_verification] => 1
[account_deposited] => 0
[document_uploaded] => 0
[lead_status] => 1
[status] => 10
[created_at] => 1468296369
[updated_at] => 1468296580
)
[_related:yii\db\BaseActiveRecord:private] => Array ( )
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default [_events:yii\base\Component:private] => Array ( ) [_behaviors:yii\base\Component:private] => Array ( ) )
现在如何在变量中获取此值。
答案 0 :(得分:1)
请确保您在类顶部添加广告的公共变量不会覆盖您的ActiveRecord ..您在活动记录中已经有相同的var名称..模型中公共var的声明会生成失败valeu的分配,你得到空的结果..
答案 1 :(得分:0)
尝试如下:
if($obj->email_verification) {
echo "Works";
}
答案 2 :(得分:0)
试
$model = PhCabinetUser::find()->all();
var_dump($model); exit;