[SOLVED] activation link error

Hi, now that I can send activation links, I retrieved it in my action and am getting an error.

here’s the url




http://yii/myapp/index.php?r=wsmembers/activate?email=test@gmail.com



and here’s my action activate function





	public function actionActivate()

	{

		$email = Yii::app()->request->getQuery('email');

		$model = new Wsmembers();

		$criteria = new CDbCriteria;

		$criteria->select = 'EmailAddress';

		$criteria->condition = 'EmailConfirmed=:value';

		$criteria->params = array(':value' => 0);

		$result = $model->find($criteria);

		

			if($result == 1)

			{

				$model->find($criteria);

				$model->EmailConfirmed = '1';

				$model->MembershipDateConfirmed = new CDbExpression('NOW()');

				$model->save();

			}

	}



did I miss something ?

try to change second "?" to "&"


http://yii/myapp/index.php?r=wsmembers/activate&email=test@gmail.com

changing the the second “?” to “&” didn’t helped at all, the page turned all white

and the row’s column from my table didn’t get updated , any other idea what’s going on?




public function actionActivate()

        {

                $email = Yii::app()->request->getQuery('email');

                $criteria = new CDbCriteria;

                $criteria->select = 'EmailAddress';

                $criteria->condition = 'EmailConfirmed=:value';

                $criteria->params = array(':value' => 0);

                $result = Wsmembers::model()->find($criteria);                

                        if($result != null)

                        {

                                $result->EmailConfirmed = '1';

                                $result->MembershipDateConfirmed = new CDbExpression('NOW()');

                                $result->save();

                        }

        }



try this

nothing happened,still all white… I turned on the CWebLogRoute of my app, I cant’ find any fishy stuffs ,

And what you expected, you even method render did’t call

Or I something don’t understand?

I was expecting it to update atleast those fields in the row even if it’s all white page

but nothing totally happened , it’s like a white screen of death, it seem like the method didn’t work at all

Try to put some echo, and you will understand if it works.

Just a question, from were is this address? It looks like you hardcoded, you shouldn’t.

Try creating the address with:




<?php echo Yii::app()->request->userHost?><?php echo Yii::app()->request->baseUrl?><?php echo CHtml::normalizeUrl(array('wsmembers/activate', 'email'=>$model->email))?>



Like that you will be sure that the address is valid.

for your question, yeah i actually embedded it in an email body like this




$message2 = "<html><body>Please click the link below to activate your membership<br />

	http://yii/myapp/index.php?r=wsmembers/activate?email=".$_POST['Wsmembers']['EmailAddress'].

	 "</body></html>";



that snippet you’ve shared, does that mean I should include that in email body ?

change


$result->save();

to




if(!$result->save())

            {

                var_dump($result->getErrors());

            }



it must show cause of problem

the things that were printed on screen are the form names and their corresponding validations

remove


 $criteria->select = 'EmailAddress';

and try once again

In your harcoded HTML put

<html><body>Please click the link below to activate your membership<br />

    &quot;. Yii::app()-&gt;createUrl('wsmembers/activate', array('email'=&gt;&#036;_POST['Wsmembers']['EmailAddress'])).


     &quot;&lt;/body&gt;&lt;/html&gt;

Use Yii to create your urls, do not try to hardcode them

i got this after i submitted the form,

no link was sent

ups sorry… I was speed writing…

Yii::app()->createUrl

weird, this is what I got from the email




Please click this below to activate your membership

/myapp/index.php?r=wsmembers/activate&email=test%40gmail.com



the http:// got ripped off. I got curious, why shouldn’t we hardcode or embed an activation link in an

email without using the yii url functions ?


........

Yii::app()->createAbsoluteUrl('wsmembers/activate', array('email'=>$_POST['Wsmembers']['EmailAddress'])).

........

Because Yii makes them taking into account your url rules() in the main.php config file. It is more error prone to hardcode them than by creating them with createUrl function…

Just check what you did:

http://yii/myapp/index.php?r=wsmembers/activate?email=test@gmail.com

and what yii’s result was:

/myapp/index.php?r=wsmembers/activate&email=test%40gmail.com

it is better to let the app handle the urls as your suggest to do in your rules() section

this one worked. thanks :)

thanks to all of you…dynamic activation link creation solved …

Good man!

Please update your forum topic as [SOLVED] (edit first post, use full editor), this way people could jump into this post finding answers to possible challenges like yours.

;)