Jump to content



Photo

Cexception - Loginform.Rememberme" Is Not Defined.


  • Please log in to reply
10 replies to this topic

#1 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 8 December 2011 - 2:55 AM

Hi,

I have tried implementing the code for a new login from the example at this link...
http://www.larryullm...-yii-framework/

When I (try) to login, this Error appears... cException - LoginForm.rememberMe" is not defined.
/opt/yii/framework/web/helpers/CHtml.php(2063)

1. The stack trace highlited the remember me code even though it was commented out. So I am assuming that <!-- out code --> is not good enough and the code should be removed. Confirm?

2. Larry's code has CHtml with the label and textfield. Is that to make these labels for this paticular form unique for this instance only?

3. Also, the descriptions I found for 'activeLabel' and 'activeLabelEx' are exactly the same (Generates a label tag for a model attribute.) so how does one determine which to use?

Larry's code:
<div>
<?php echo CHtml::activeLabel($form,'email'); ?>
<?php echo CHtml::activeTextField($form,'email') ?>
</div>

My code:
<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model,'email'); ?>
		<?php echo $form->error($model,'email'); ?>
	</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>.
		</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>
-->
-->

I am just beginning with Yii because I do not know PHP!
  • 0

#2 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 8 December 2011 - 4:18 AM

Okay, I have changed the form.php code to match Larry's

And now,there is this error when I try to login...

PHP Error - Undefined variable: form
/opt/lampp/htdocs/debus/protected/views/site/login.php(15)

The stack trace
#4 – /opt/lampp/htdocs/debus/protected/controllers/SiteController.php(126): CController->render("login", array("model" => LoginForm))
highlites this code:line 126...
// display the login form
 
126		 $this->render('login',array('model'=>$model));
127	 }

siteController
/**
	 * Displays the login page
	 */
	public function actionLogin()
	{
		$model=new LoginForm;
 
		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
 
		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		$this->render('login',array('model'=>$model));
	}

I am guessing that it has to do with the CActiveForm...?
  • 0

#3 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,842 posts
  • LocationState College, PA (USA)

Posted 9 December 2011 - 10:24 PM

Do you really not know PHP? Not only do you need to know PHP, you need to be quite good at it before you ever consider using a framework. A framework isn't a replacement for a language, it's a way to use the language more efficiently.
  • 0

#4 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 10 December 2011 - 11:53 PM

I have to start somewhere!

Yii seemed to be a good starting point to learn because it offers a site with working examples. I learn better using the hands on approach.

I knew that modifications would be needed but there seemed to be plenty of forums and sites offering help, like yours. I learned HTML and CSS with the help of WebProWorld members, I can learn anything I set my mind to, with help of course.

Larry, your tutorials are greatly appreciated, you are obviously very talented and generous. I have come here because it was your example and if you didn't have time then perhaps another member here may be inclined to help.

So, I am guessing the problem is in the controller for the login form because your code changed the form to a static CHtml form and the error stated that there was an undefined variable:form.

Do I need to change the 'echo CActiveForm::...' to 'echo CHtmlForm::validate...' in the controller? Something tells me it isn't as simple as that.
  • 0

#5 Jonathon

Jonathon

    Advanced Member

  • Members
  • PipPipPip
  • 1,022 posts

Posted 11 December 2011 - 12:12 PM

Much as you do have to start somewhere, at some point you will want something that isn't documented well or you will need to modify it (at a PHP / MySQL level) to meet your needs at which point you will be fairly helpless. The stuff on Yii isn't helping you understand the language or what it's doing at a rudimentary level, it's showing you how to build an application and much as I don't know what you've read, I an assuming its a tutorial on how to implement something to Yii, are you learning or perhaps just copying what somebody else has written? By all means get as much out of Yii as you can but you really need to learn procedural PHP and then OO PHP to have any chance of using the language and framework well. PHP is not like CSS and HTML, they are pretty easy to grasp, PHP is quick to pick up (procedurally) but to really become strong at it takes time and exposure and OOP I would say is a level ahead in terms of logic/organisation. Finally a big part of being a decent programmer is being able to debug well, if your new to PHP then you have no experience in errors and how to deal with them.
  • 1

#6 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 December 2011 - 6:17 PM

Hi Johnathon, I appreciate your comments, and I understand what you are saying. Yes, PHP is much more difficult than HTML and CSS however there was a time that those were greek to me as well.

I learned HTML by fixing errors that were the result of designing with a FrontPage template. Now I can create a page from scratch using notepad. I learned CSS pretty much the same way. A very nice member of the WPW forum gave me a template with a css file to play with.

At first everything may not make sense but over time it all starts to come together with research and practice. Larry's tutorial and the Yii files comment on what things are and what the code is doing which I find very helpful and if something doesn't register at first then eventually it will.

Back to the topic, I read through the comments again...
http://www.larryullm...-yii-framework/

and found this post by, Jens, which has solved my problem! it is as simple as...

Oh I’m sorry.. I had to change the last line of function actionLogin() in SiteController.php. It has to be “$this->render(‘login’,array(‘form’=>$model));” and not “$this->render(‘login’,array(‘model’=>$model));”.
Best regards!

Adding this site controller change to the tutorial would make the tutorial complete.

What I don't get is why the command for rendering the form is the last line, it seems the form render would be first and then input and validation. But I guess it will all make more sense the more I learn.
  • 0

#7 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,842 posts
  • LocationState College, PA (USA)

Posted 11 December 2011 - 8:04 PM

I have to start somewhere!


Absolutely! And you should start by learning PHP. The Yii framework makes dynamic Web development with PHP faster, but PHP HAS to come first.

Yii seemed to be a good starting point to learn because it offers a site with working examples. I learn better using the hands on approach.


Yii is absolutely not a good starting point. You can do working examples in PHP.

I knew that modifications would be needed but there seemed to be plenty of forums and sites offering help, like yours. I learned HTML and CSS with the help of WebProWorld members, I can learn anything I set my mind to, with help of course.


Certainly you may be capable of learning anything if you set your mind to it. My point is you should learn PHP first, then learn Yii. You are only making things harder on yourself trying to learn Yii first.

Larry, your tutorials are greatly appreciated, you are obviously very talented and generous. I have come here because it was your example and if you didn't have time then perhaps another member here may be inclined to help.


Thank you for the nice words. It is appreciated. The forums are here for people to get help. It's not a question of my having the time. I think it's completely impractical to try learning Yii without knowing Web development with PHP.

I like analogies, so consider this one: "One Hundred Years of Solitude" is my favorite book of all time. I understand it's even better in the original Spanish. So should I go ahead and start reading it in Spanish, although I don't know Spanish, assuming that I'll pick up Spanish along the way? Or would that be imprudent and a waste of my time? As opposed to, you know, learning Spanish first, and then reading the book?

In any case, you've had two responses along the same lines and since you seem set on putting the cart before the horse, I'll wish you the best of luck in that endeavor. If you get to a point where you've learned PHP, I'll be happy to answer your PHP or Yii questions then.
  • 0

#8 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 December 2011 - 11:20 PM

The forums are here for people to get help.


If you get to a point where you've learned PHP, I'll be happy to answer your PHP or Yii questions then.

Larry, I can respect your stance, it is your knowledge and talent to share as you wish. You do not want to teach kindergarten. Could you recommend some of the best beginners classes/sites for learning Web development with PHP I would certainly go there. I have the PHP.net site bookmarked for reference.

Just know that, at the same time I will continue with the Yii because I am very close to having a basic working site like I need it to for now.( I will go elsewhere when asking for help until I learn PHP.) I do want to learn PHP because I know that I will be expanding on this site.
  • 0

#9 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,842 posts
  • LocationState College, PA (USA)

Posted 12 December 2011 - 8:52 AM

You do not want to teach kindergarten.


No, no, no. You've got this all backwards. It's not that I don't want to teach kindergarten. I don't want to teach Calculus to someone that doesn't think they need to learn algebra first.

Could you recommend some of the best beginners classes/sites for learning Web development with PHP I would certainly go there. I have the PHP.net site bookmarked for reference.


I've written several books that teach PHP, including what are widely considered to be among the best for beginners, but unfortunately I don't know of any classes/sites I could recommend. Nothing better than a Google search anyway. Perhaps someone else might have a recommendation.
  • 0

#10 clicken

clicken

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 12 December 2011 - 10:14 AM

Larry, you are so cool! I mean that. :) Would I find your books at the library?

It isn't that I don't think that I need to learn PHP in order to expand the Yii framework but rather, and I will use your horse and cart analogy: Yii is horsepower driven so that the cart and horse are together. Yii is like an Indy car, which I wouldn't dare try to drive at high speeds without lots of successful experience first And most important, a qualified trainer!

Due to your tutorials, I was able to log-in to my yii site as demo/demo and submit a referral to the referral db table with permission to view my entry and update my entry if needed. Then logged in as admin/admin I could view entries, update or delete them.

By doing that little bit I learned a little bit about PHP and Mysql. (yes I am new to that too.)

Now I get to learn some more as I try to figure out why and how to get the login password to work.

So, if I had not mentioned that I do not know PHP then you would have given me guidence? Talking too much has always been one of my faults!
  • 0

#11 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,842 posts
  • LocationState College, PA (USA)

Posted 12 December 2011 - 11:10 AM

Larry, you are so cool! I mean that. :) Would I find your books at the library?


Thanks. Yes, they should be available at your library. Or, if not, you can request that your library borrows a copy from another library.

It isn't that I don't think that I need to learn PHP in order to expand the Yii framework but rather, and I will use your horse and cart analogy: Yii is horsepower driven so that the cart and horse are together. Yii is like an Indy car, which I wouldn't dare try to drive at high speeds without lots of successful experience first And most important, a qualified trainer!


Well, to be clear as to why you need to know PHP first, as you've probably discovered, Yii is great and does a lot of work for you. Just following the documentation and a couple of tutorials, Yii will do about 80% of the work for you. However, it's the 20% that really matters, that really differentiates one site from another, and that 20% is hard, and requires sound knowledge of PHP and OOP.

So, if I had not mentioned that I do not know PHP then you would have given me guidence? Talking too much has always been one of my faults!


Pretty quickly I would have figured it out. Also, as Jonathon pointed out, what learning PHP gives you is debugging skills, and it would have been quickly clear that you were unable to apply basic debugging skills when you have problems.
  • 0