2017-04-20 4 views
-1

私はプリントアウトしたYii2のモデルを持っています。私はロゴ属性に値test.jpgを保存したいと思っています。このモデルからこの価値をどのように得ることができますか?私はpirnt_r($ model->属性)を試しましたが、ロゴフィールドに空の値を返します。 inatailの空の値をスキップしてロゴフィールドのtest.jpg値を取得する方法はありますか?

backend\models\UserProfiles Object 
(
[logo] => 
[cover] => 
[_attributes:yii\db\BaseActiveRecord:private] => Array 
    (
     [id] => 2 
     [date_created] => 2017-04-19 08:02:29 
     [status] => 1 
     [logo] => test.jpg 
     [cover] => test (2).jpg 
     [website] => wqeqww 
     [address] => qweqweqw 
     [about] => qweqwe 
     [phone] => qweqweq 
     [full_name] => qweqwe 
     [city] => qweqweq 
     [country] => qweqeqe 
     [profile_type] => Type 1 
     [user_id] => 2 
    ) 

[_oldAttributes:yii\db\BaseActiveRecord:private] => Array 
    (
     [id] => 2 
     [date_created] => 2017-04-19 08:02:29 
     [status] => 1 
     [logo] => test.jpg 
     [cover] => test (2).jpg 
     [website] => wqeqww 
     [address] => qweqweqw 
     [about] => qweqwe 
     [phone] => qweqweq 
     [full_name] => qweqwe 
     [city] => qweqweq 
     [country] => qweqeqe 
     [profile_type] => Type 1 
     [user_id] => 2 
    ) 

[_related:yii\db\BaseActiveRecord:private] => Array 
    (
    ) 

[_errors:yii\base\Model:private] => 
[_validators:yii\base\Model:private] => ArrayObject Object 
    (
     [storage:ArrayObject:private] => Array 
      (
       [0] => yii\validators\RequiredValidator Object 
        (
         [skipOnEmpty] => 
         [requiredValue] => 
         [strict] => 
         [message] => {attribute} cannot be blank. 
         [attributes] => Array 
          (
           [0] => id 
           [1] => user_id 
          ) 

         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

       [1] => yii\validators\NumberValidator Object 
        (
         [integerOnly] => 1 
         [max] => 
         [min] => 
         [tooBig] => 
         [tooSmall] => 
         [integerPattern] => /^\s*[+-]?\d+\s*$/ 
         [numberPattern] => /^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/ 
         [attributes] => Array 
          (
           [0] => id 
           [1] => user_id 
          ) 

         [message] => {attribute} must be an integer. 
         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [skipOnEmpty] => 1 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

       [2] => yii\validators\StringValidator Object 
        (
         [length] => 
         [max] => 
         [min] => 
         [message] => {attribute} must be a string. 
         [tooShort] => 
         [tooLong] => 
         [notEqual] => 
         [encoding] => UTF-8 
         [attributes] => Array 
          (
           [0] => address 
           [1] => about 
          ) 

         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [skipOnEmpty] => 1 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

       [3] => yii\validators\FileValidator Object 
        (
         [extensions] => Array 
          (
           [0] => jpg 
           [1] => png 
          ) 

         [checkExtensionByMimeType] => 1 
         [mimeTypes] => Array 
          (
          ) 

         [minSize] => 
         [maxSize] => 
         [maxFiles] => 1 
         [message] => File upload failed. 
         [uploadRequired] => Please upload a file. 
         [tooBig] => The file "{file}" is too big. Its size cannot exceed {formattedLimit}. 
         [tooSmall] => The file "{file}" is too small. Its size cannot be smaller than {formattedLimit}. 
         [tooMany] => You can upload at most {limit, number} {limit, plural, one{file} other{files}}. 
         [wrongExtension] => Only files with these extensions are allowed: {extensions}. 
         [wrongMimeType] => Only files with these MIME types are allowed: {mimeTypes}. 
         [attributes] => Array 
          (
           [0] => logo 
           [1] => cover 
          ) 

         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [skipOnEmpty] => 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

       [4] => yii\validators\StringValidator Object 
        (
         [length] => 
         [max] => 45 
         [min] => 
         [message] => {attribute} must be a string. 
         [tooShort] => 
         [tooLong] => {attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}. 
         [notEqual] => 
         [encoding] => UTF-8 
         [attributes] => Array 
          (
           [0] => date_created 
           [1] => status 
           [2] => logo 
           [3] => cover 
           [4] => website 
           [5] => phone 
           [6] => full_name 
           [7] => city 
           [8] => country 
           [9] => profile_type 
          ) 

         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [skipOnEmpty] => 1 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

       [5] => yii\validators\ExistValidator Object 
        (
         [targetClass] => backend\models\User 
         [targetAttribute] => Array 
          (
           [user_id] => id 
          ) 

         [filter] => 
         [allowArray] => 
         [targetAttributeJunction] => and 
         [attributes] => Array 
          (
           [0] => user_id 
          ) 

         [message] => {attribute} is invalid. 
         [on] => Array 
          (
          ) 

         [except] => Array 
          (
          ) 

         [skipOnError] => 1 
         [skipOnEmpty] => 1 
         [enableClientValidation] => 1 
         [isEmpty] => 
         [when] => 
         [whenClient] => 
         [_events:yii\base\Component:private] => Array 
          (
          ) 

         [_behaviors:yii\base\Component:private] => 
        ) 

      ) 

    ) 

[_scenario:yii\base\Model:private] => default 
[_events:yii\base\Component:private] => Array 
    (
    ) 

[_behaviors:yii\base\Component:private] => Array 
    (
    ) 

答えて

1

あなたがそこに印刷を参照して直接アクセスすることはできませんBaseActiveRecord、の私有財産_attributesの一部です。 yii \ db \ BaseActiveRecordクラスを見ると、ロゴ属性にアクセスする方法がわかります。

あなたは試みることができる:

$モデル - >のgetAttribute( 'ロゴ')

それとも $モデル - >ロゴ

ActiveBaseRecordのマジックメソッド "__get" を使用する必要があり、後者それが動作する可能性があります。私が見ている問題は、あなたのクラスにはlogoという名前のプロパティがあり、これが複雑になる可能性があるということです。

+0

解説を編集して説明を加えてください。コードのみの回答は、今後のSO読者の教育にはほとんど役に立ちません。あなたの答えは低品質であるためにモデレーションキューにあります。 – mickmackusa

関連する問題