Yii Framework Forum: Fatal error: a member function getAttributeLabel() - Yii Framework Forum

Jump to content

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

Fatal error: a member function getAttributeLabel() Rate Topic: -----

#1 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 09 December 2010 - 04:17 AM

Fatal error: Call to a member function getAttributeLabel() on a non-object in E:\xampp\htdocs\yii\framework\web\helpers\CHtml.php on line 1136


I could not get any idea, so I need your help.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,341
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 04:27 AM

Just this error line does not say much...

Post here full stack trace.. or the some code that you added before the error appeared...

---

From the error line I see that this is a call to activeLabel()
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 09 December 2010 - 04:47 AM

View Postmdomba, on 09 December 2010 - 04:27 AM, said:

Just this error line does not say much...

Post here full stack trace.. or the some code that you added before the error appeared...

---

From the error line I see that this is a call to activeLabel()




File location: mySiteName/protected/views/site/index.php Here I wanted to put those forms. The code is listed below:

<?php $this->pageTitle=Yii::app()->name; ?>

<p style="width:200px; float:left; font-family:fantasy; font-size:12px; color:"><?php echo CHtml::encode(Yii::app()->name); ?> helps you connect and share with the people in your life.</p>

<div class="registrationform">
	<div class="form">
	<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'login-form',
	'enableAjaxValidation'=>true,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<div class="row">
		<?php echo $form->labelEx($model,'username'); ?>
		<?php echo $form->textField($model,'username'); ?>
		<?php echo $form->error($model,'username'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php echo $form->passwordField($model,'password'); ?>
		<?php echo $form->error($model,'password'); ?>
		<p class="hint">
			Hint: You may login with <tt>demo/demo</tt> or <tt>admin/admin</tt>.
		</p>
	</div>

	<div class="row rememberMe">
		<?php echo $form->checkBox($model,'rememberMe'); ?>
		<?php echo $form->label($model,'rememberMe'); ?>
		<?php echo $form->error($model,'rememberMe'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Login'); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->
</div>

0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,341
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 04:57 AM

This code seems OK... check the call that renders this view if you are sending some value to $model
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 09 December 2010 - 05:15 AM

View Postmdomba, on 09 December 2010 - 04:57 AM, said:

This code seems OK... check the call that renders this view if you are sending some value to $model


I have not made model. Can it be by any name? or i need to match with the folder name, as my folder is site so does my module should be site?
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,341
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 05:18 AM

If you don't have a model.. than you cannot use this code...

The code
$form->labelEx($model,'username');

Renders an HTML label for a model attribute in this case $model->username.
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 09 December 2010 - 05:34 AM

View Postmdomba, on 09 December 2010 - 05:18 AM, said:

If you don't have a model.. than you cannot use this code...

The code
$form->labelEx($model,'username');

Renders an HTML label for a model attribute in this case $model->username.



But as there is already LoginForm.php (protected/models/LoginForm.php). It should work , shouldn't it?
I tried to echo the value of $model; but it returns null (nothing).
0

#8 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,341
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 05:42 AM

LoginForm.php is the model class...

The actionLogin() in SiteController.php creates a new instance of that model and renders the view with this line

$this->render('login',array('model'=>$model));


So that in the view - index.php $model is an instance of the model LoginForm...

Hope you understant this...

Try to study the default code generated by yiic... and if you haven't done so... read the Definitive guide to Yii

if you need help... just ask...
Find more about me.... btw. Do you know your WAN IP?
0

#9 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 09 December 2010 - 05:46 AM

View Postmdomba, on 09 December 2010 - 05:42 AM, said:

LoginForm.php is the model class...

The actionLogin() in SiteController.php creates a new instance of that model and renders the view with this line

$this->render('login',array('model'=>$model));


So that in the view - index.php $model is an instance of the model LoginForm...

Hope you understant this...

Try to study the default code generated by yiic... and if you haven't done so... read the Definitive guide to Yii

if you need help... just ask...




Thank you mdomba for your kind support. I will try once and if get prob. I will seek your help. Thanks again.


0

#10 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 09 December 2010 - 06:48 AM

By the way:
This forum is for reporting bugs.
Not in your own code, though. B)
"Less noise - more signal"
0

#11 User is offline   sikoshi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-March 09
  • Location:Almaty, Kazakhstan

Posted 31 January 2013 - 06:44 AM

overriding getId() method in UserIdentity can raise this problem
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