2
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;
}

这是我在模型中的代码。我试图返回 $_temp 因此我做了 $this->temp = $temp. 我的问题是它返回NULL。

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('swap.test@yahoo.com.sg', '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。有什么解决办法吗?

4

3 回答 3

1

看起来您正在创建两个DbTable_Register对象,在第一个对象上调用 reset,而不是第二个对象,然后您试图从第二个对象获取临时密码。第二个不会有 temp 因为你没有调用resetPass第二个对象。

尝试改变:

$reset = new Application_Model_DbTable_Register();
$reset->resetPass($userid);

$pswd = new Application_Model_DbTable_Register();
$pswd = $pswd->getTemp();
var_dump($pswd);

至:

$reset = new Application_Model_DbTable_Register();
$reset->resetPass($userid);
$pswd  = $reset->getTemp();

var_dump($pswd);

看看这是否有效。

于 2012-08-11T19:16:27.570 回答
1

你正在使用

 return parent::$this->_temp;

是否$_temp存在于父对象中?看起来您是在 THIS 对象中定义它,并且它不存在于您(希望)继承的父对象中。

于 2012-08-11T18:11:48.743 回答
0

首先:检查Application_Model_Register::generatePass(); 功能

第二:在resetPass功能上删除这个:

$this->_temp = (string) $temp;

并添加:

if (empty($temp)){
    $this->_temp = (string) $temp;
}

它是否返回某个值?如果不是,则generatePass()函数是错误的。

第三:在您的控制器上

$reset = new Application_Model_DbTable_Register();
$reset->resetPass($userid);
$pswd = new Application_Model_DbTable_Register();
$pswd = $pswd->getTemp();
var_dump($pswd);

不要制作像$reset$pswd这样的双重对象。

尝试 :

$reset = new Application_Model_DbTable_Register();
$pswd = $reset->resetPass($userid)->getTemp();
echo "<pre>";
print_r($pswd);

如我错了请纠正我。

于 2012-08-11T19:35:10.543 回答