Yii Framework Forum: Yii-User Profile Field Issues - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii-User Profile Field Issues Rate Topic: -----

#1 User is offline   MalcolmT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 14

Posted 17 January 2014 - 07:21 PM

I keep coming across two issues when creating new profile user fields. I'm using 0.3-88 of yii-user.

I created a field, "city" but out of tiredness, I gave it a range of states, i.e. AL;AK;AZ etc. I had an issue with it at first, it didn't like all the states in there and was giving a string to array conversion error. So I reduced it to just AL;AK to try it and it worked. Then I edited the field in the database directly (using MySql Workbench) to do all the states and it was still happy. Then I realized I did that to the city field. So I changed it back to a normal text field, and added a new field named "state". I went through the same steps, but I still get errors on this field and cannot get it to work.

Editing the field appears to work. But then if I click on a user to view them, I get this error (domain.com/index.php/user/admin/view/id/1):

Array to string conversion
/opt/yii/framework/zii/widgets/CDetailView.php(238)

226             echo CHtml::closeTag($this->tagName);
227     }
228 
229     /**
230      * This method is used by run() to render item row
231      *
232      * @param array $options config options for this item/attribute from {@link attributes}
233      * @param string $templateData data that will be inserted into {@link itemTemplate}
234      * @since 1.1.11
235      */
236     protected function renderItem($options,$templateData)
237     {
238         echo strtr(isset($options['template']) ? $options['template'] : $this->itemTemplate,$templateData);
239     }
240 
241     /**
242      * @return CFormatter the formatter instance. Defaults to the 'format' application component.
243      */
244     public function getFormatter()
245     {
246         if($this->_formatter===null)
247             $this->_formatter=Yii::app()->format;
248         return $this->_formatter;
249     }
250 

Stack Trace
#0	
+  /opt/yii/framework/zii/widgets/CDetailView.php(238): strtr("<tr class="{class}"><th>{label}</th><td>{value}</td></tr> ", array("{label}" => "State", "{class}" => "even", "{value}" => array("AL" => "AL", "AK" => "AK")))
#1	
+  /opt/yii/framework/zii/widgets/CDetailView.php(220): CDetailView->renderItem(array("label" => "State", "name" => "state", "type" => "raw", "value" => array("AL" => "AL", "AK" => "AK")), array("{label}" => "State", "{class}" => "even", "{value}" => array("AL" => "AL", "AK" => "AK")))
#2	
+  /opt/yii/framework/web/CBaseController.php(173): CDetailView->run()
#3	
–  /var/www/domain/protected/modules/user/views/admin/view.php(57): CBaseController->widget("zii.widgets.CDetailView", array("data" => User, "attributes" => array("id", "username", array("label" => "Address 1", "name" => "address1", "type" => "raw", "value" => ""), array("label" => "Address 2", "name" => "address2", "type" => "raw", "value" => ""), ...)))
52     );
53     
54     $this->widget('zii.widgets.CDetailView', array(
55         'data'=>$model,
56         'attributes'=>$attributes,
57     ));
58     
59 
60 ?>


And if I try to edit the user (domain.com/index.php/user/admin/update/id/1):

Property "Profile.state" is not defined.
/opt/yii/framework/db/ar/CActiveRecord.php(145)

133      */
134     public function __get($name)
135     {
136         if(isset($this->_attributes[$name]))
137             return $this->_attributes[$name];
138         elseif(isset($this->getMetaData()->columns[$name]))
139             return null;
140         elseif(isset($this->_related[$name]))
141             return $this->_related[$name];
142         elseif(isset($this->getMetaData()->relations[$name]))
143             return $this->getRelated($name);
144         else
145             return parent::__get($name);
146     }
147 
148     /**
149      * PHP setter magic method.
150      * This method is overridden so that AR attributes can be accessed like properties.
151      * @param string $name property name
152      * @param mixed $value property value
153      */
154     public function __set($name,$value)
155     {
156         if($this->setAttribute($name,$value)===false)
157         {

Stack Trace
#0	
+  /opt/yii/framework/db/ar/CActiveRecord.php(145): CComponent->__get("state")
#1	
+  /opt/yii/framework/web/helpers/CHtml.php(2529): CActiveRecord->__get("state")
#2	
+  /opt/yii/framework/web/helpers/CHtml.php(1802): CHtml::resolveValue(Profile, "state")
#3	
+  /opt/yii/framework/web/widgets/CActiveForm.php(847): CHtml::activeDropDownList(Profile, "state", array("AL" => "AL", "AK" => "AK"), array())
#4	
–  /var/www/domain/protected/modules/user/views/admin/_form.php(54): CActiveForm->dropDownList(Profile, "state", array("AL" => "AL", "AK" => "AK"))
49         <?php echo $form->labelEx($profile,$field->varname); ?>
50         <?php 
51         if ($widgetEdit = $field->widgetEdit($profile)) {
52             echo $widgetEdit;
53         } elseif ($field->range) {
54             echo $form->dropDownList($profile,$field->varname,Profile::range($field->range));
55         } elseif ($field->field_type=="TEXT") {
56             echo CHtml::activeTextArea($profile,$field->varname,array('rows'=>6, 'cols'=>50));
57         } else {
58             echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255)));
59         }


and finally, as a logged in user clicking Profile at the top (domain.com/index.php/user/profile):

htmlspecialchars() expects parameter 1 to be string, array given
/opt/yii/framework/web/helpers/CHtml.php(103)

091      */
092     private static $_modelNameConverter;
093 
094     /**
095      * Encodes special characters into HTML entities.
096      * The {@link CApplication::charset application charset} will be used for encoding.
097      * @param string $text data to be encoded
098      * @return string the encoded data
099      * @see php.net/manual/en/function.htmlspecialchars.php
100      */
101     public static function encode($text)
102     {
103         return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset);
104     }
105 
106     /**
107      * Decodes special HTML entities back to the corresponding characters.
108      * This is the opposite of {@link encode()}.
109      * @param string $text data to be decoded
110      * @return string the decoded data
111      * @see php.net/manual/en/function.htmlspecialchars-decode.php
112      * @since 1.1.8
113      */
114     public static function decode($text)
115     {

Stack Trace
#0	
+  /opt/yii/framework/web/helpers/CHtml.php(103): htmlspecialchars(array("AL" => "AL", "AK" => "AK"), 3, "UTF-8")
#1	
–  /var/www/domain/protected/modules/user/views/profile/profile.php(34): CHtml::encode(array("AL" => "AL", "AK" => "AK"))
29             foreach($profileFields as $field) {
30                 //echo "<pre>"; print_r($profile); die();
31             ?>
32     <tr>
33         <th class="label"><?php echo CHtml::encode(UserModule::t($field->title)); ?></th>
34         <td><?php echo (($field->widgetView($profile))?$field->widgetView($profile):CHtml::encode((($field->range)?Profile::range($field->range,$profile->getAttribute($field->varname)):$profile->getAttribute($field->varname)))); ?></td>
35     </tr>
36             <?php
37             }//$profile->getAttribute($field->varname)
38         }
39     ?>
#2	
+  /opt/yii/framework/web/CBaseController.php(126): require("/var/www/domain/protected/modules/user/views/profile/pro...")
#3	
+  /opt/yii/framework/web/CBaseController.php(95): CBaseController->renderInternal("/var/www/domain/protected/modules/user/views/profile/pro...", array("model" => User, "profile" => Profile), true)
#4	
+  /opt/yii/framework/web/CController.php(869): CBaseController->renderFile("/var/www/domain/protected/modules/user/views/profile/pro...", array("model" => User, "profile" => Profile), true)
#5	
+  /opt/yii/framework/web/CController.php(782): CController->renderPartial("profile", array("model" => User, "profile" => Profile), true)
#6	
–  /var/www/domain/protected/modules/user/controllers/ProfileController.php(21): CController->render("profile", array("model" => User, "profile" => Profile))
16     {
17         $model = $this->loadUser();
18         $this->render('profile',array(
19             'model'=>$model,
20             'profile'=>$model->profile,
21         ));
22     }
23 
24 
25     /**
26      * Updates a particular model.


Any guidance would be appreciated. I like the potential of the extension, but this is frustrating.
MT2
0

#2 User is offline   MalcolmT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 14

Posted 17 January 2014 - 09:33 PM

I think this is solved. I'm not sure how or why though. It's just working now. Maybe a caching thing? I thought that earlier, and turned Memcache off, and I'm not using file caching either, so I'm not sure. But it works for now. I have other fields to add, so maybe I'll be back with more problems :)
0

#3 User is offline   MalcolmT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 14

Posted 17 January 2014 - 09:51 PM

Here we go again. I created a new field, varchar(5) of 'Zip'. it shows up when I click Profile, or when I view a user (says 'not set'), but trying to edit my own profile or editing a user profile from the Admin, results in Property "Profile.zip" is not defined.. I'm going to wait and see if this fixes itself, but does anyone have experience with this? Am I missing something?

Thanks,
MT2

Edit: It just started working, again, with no obvious changes on my side.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users