protected $_name = 'usertable'; //table name for database [Impt] Please change accordingly
protected $_temp;
function resetPass($userid)
{
$pass = new Application_Model_Register();
$salt = $pass->generateSalt();
$temp = $pass->generatePass();
$this->_temp = (string) $temp;
$data = array(
'password' => hash("sha256", ($salt. $temp)),
'salt' => $salt, //get salt from generateSalt()
);
//$auth= Zend_Auth::getInstance(); //declare zend_auth to get instance
//$user= $auth->getIdentity(); //get identity of user
//$userid = $user->userid; //get userid of user
echo $temp;
$this->update($data, 'userid = '. (int)($userid));
return $this;
}
function getTemp()
{
return parent::$this->_temp;
}
这是我在Model中的代码。我试图返回$ _temp,因此我做了$ this-> temp = $ temp。我的问题是,它返回NULL。变量一直返回NULL,php
public function sendEmail($email)
{
$email = $_POST['email'];
$userid = '30';
$reset = new Application_Model_DbTable_Register();
$reset->resetPass($userid);
$pswd = new Application_Model_DbTable_Register();
$pswd = $pswd->getTemp();
var_dump($pswd);
$mail = new Zend_Mail();
$mail->setFrom('[email protected]', 'Inexorable Beauty');
$mail->addTo($email, $email);
$mail->setSubject('Inexorable Beauty: Password Reset');
$mail->setBodyText('Dear Customer,
You have requested to reset your password.
This is the temporary password: '.$pswd.'
Please log in immediately and change your password.
Thank You.
Yours Sincerely,
Inexorable Beauty');
$mail->send();
if($mail->send())
{
echo "Email successfully sent!";
}
else
{
echo "Email was not sent";
}
}
这是我的控制器代码。我正尝试将临时密码发送给客户的电子邮件。我从我的模型中调用getTemp()函数来获取passwd字符串,但正如你所看到的,我做了var_dump($ pswd)并且它一直返回NULL。任何解决方案
谢谢你们。我在$ _temp前添加了一个全局变量,它工作正常。似乎变量不能在函数之外使用。 http://php.net/manual/en/language.variables.scope.php – 2012-08-11 20:48:44