archi
(Kazineel)
December 17, 2009, 4:25pm
1
Hi,
I want user id in the TextField from the user table who is login, I can print the user id
<?php echo Yii::app()->user->id ; ?>
when i use this in the text field it’s not working and got error
<?php echo CHtml::activeTextField($model,‘Yii::app()->user->id’,array(‘size’=>5,‘maxlength’=>5)); ?>
Error
public function __get($name)
00424: {
00425: if(isset($this->_attributes[$name]))
00426: return $this->_attributes[$name];
00427: else if(isset($this->getMetaData()->columns[$name]))
00428: return null;
00429: else if(isset($this->_related[$name]))
00430: return $this->_related[$name];
00431: else if(isset($this->getMetaData()->relations[$name]))
00432: return $this->getRelated($name);
00433: else
00434: return parent::__get($name);
00435: }
can anyone help me where i need to change?
archi
(Kazineel)
December 17, 2009, 7:18pm
3
Hey Tommy,
I got this error after remove quotes
<?php echo CHtml::activeTextField($model,Yii::app()->user->id,array(‘size’=>5,‘maxlength’=>5)); ?>
Error:
Property "ShopRecords.3" is not defined.
Source File
/var/www/yii/db/ar/CActiveRecord.php(434)
00422: */
00423: public function __get($name)
00424: {
00425: if(isset($this->_attributes[$name]))
00426: return $this->_attributes[$name];
00427: else if(isset($this->getMetaData()->columns[$name]))
00428: return null;
00429: else if(isset($this->_related[$name]))
00430: return $this->_related[$name];
00431: else if(isset($this->getMetaData()->relations[$name]))
00432: return $this->getRelated($name);
00433: else
00434: return parent::__get($name);
00435: }
tri
(tri - Tommy Riboe)
December 17, 2009, 8:10pm
4
archi:
Hey Tommy,
I got this error after remove quotes
<?php echo CHtml::activeTextField($model,Yii::app()->user->id,array(‘size’=>5,‘maxlength’=>5)); ?>
Error:
Property "ShopRecords.3" is not defined.
Source File
…
Sorry, I didn’t look very close, did I. You’re supposed to pass the name of an attribute in the model. If you wan’t to select the user record corresponding to the logged in user, you need to add a condition to your query. Something like
User::model()->find('UserId="'.Yii::app()->user->id.'"')
(from memory)
Edit:
Had another look. I think you want to fill in the user name in a fresh form. Assign the value before calling activeTextField(). Something like
$model->UserName = Yii::app()->user->id;
/Tommy
mbi
(mbi)
December 17, 2009, 8:35pm
5
the second parameter has to be an attribute of the model
archi
(Kazineel)
December 17, 2009, 8:43pm
6
Hey Tommy,
You re greattttttttttttt.
Thanks