sasori
(Nemo Md5)
November 9, 2010, 10:51am
1
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 ?
rudenich
(Rudenich)
November 9, 2010, 11:02am
2
try to change second "?" to "&"
http://yii/myapp/index.php?r=wsmembers/activate&email=test@gmail.com
sasori
(Nemo Md5)
November 9, 2010, 11:06am
3
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?
rudenich
(Rudenich)
November 9, 2010, 11:16am
4
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
sasori
(Nemo Md5)
November 9, 2010, 11:24am
5
nothing happened,still all white… I turned on the CWebLogRoute of my app, I cant’ find any fishy stuffs ,
rudenich
(Rudenich)
November 9, 2010, 11:40am
6
And what you expected, you even method render did’t call
Or I something don’t understand?
sasori
(Nemo Md5)
November 9, 2010, 11:54am
7
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
zaccaria
(Matteo Falsitta)
November 9, 2010, 11:54am
8
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.
sasori
(Nemo Md5)
November 9, 2010, 11:58am
9
zaccaria:
Try to put some echo, and you will understand if it works.
Just a question, from were is this address? It looks like you manually, 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))?>
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 ?
rudenich
(Rudenich)
November 9, 2010, 12:06pm
10
change
$result->save();
to
if(!$result->save())
{
var_dump($result->getErrors());
}
it must show cause of problem
sasori
(Nemo Md5)
November 9, 2010, 12:10pm
11
the things that were printed on screen are the form names and their corresponding validations
rudenich
(Rudenich)
November 9, 2010, 12:15pm
12
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 />
". Yii::app()->createUrl('wsmembers/activate', array('email'=>$_POST['Wsmembers']['EmailAddress'])).
"</body></html>
Use Yii to create your urls, do not try to hardcode them
sasori
(Nemo Md5)
November 9, 2010, 12:37pm
14
In your harcoded HTML put
<html><body>Please click the link below to activate your membership<br />
". Yii::app()->request->createUrl('wsmembers/activate', array('email'=>$_POST['Wsmembers']['EmailAddress'])).
"</body></html>
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
sasori
(Nemo Md5)
November 9, 2010, 12:54pm
16
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 ?
phreak
(Phreak)
November 9, 2010, 12:59pm
17
........
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
sasori
(Nemo Md5)
November 9, 2010, 1:10pm
19
this one worked. thanks
phreak:
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
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.