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

2 つのオブジェクトを作成しているように見えますがDbTable_Register、最初のオブジェクトではリセットを呼び出しますが、2 番目ではなく、2 番目のオブジェクトから一時パスワードを取得しようとしています。2 番目のオブジェクトを呼び出していないため、2 番目のオブジェクトには 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(); を確認します。関数

2番目:resetPass関数でこれを削除します:

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

そして追加:

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

何かの値を返しますか?そうでない場合は、generatePass()関数が間違っています。

3番目:あなたのコントローラーで

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

$reset$pswdのような double オブジェクトを作成しないでください。

してみてください:

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

私が間違っている場合は修正してください。

于 2012-08-11T19:35:10.543 に答える