【发布时间】:2017-11-05 18:26:47
【问题描述】:
我在我的 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 ( ) )
现在如何在变量中获取这个值。
【问题讨论】:
-
而不是做回声,通过 var_dump 检查一次,我想它必须是布尔值
-
是的,它是布尔变量。那么如何打印呢?
-
为什么在
ActiveRecord类模型中使用成员变量 -
Echo 无法在此工作。做var_dump,在if条件下可以直接使用
-
if 条件下如何使用。我试过这个 if($obj['email_verification']==1) { echo "works"; } 但它不工作