1

我正在编写我的第一个 CakePHP 应用程序,并且正在编写密码重置表单的第二部分,其中用户收到了一封包含网站链接的电子邮件,当他们点击它时,他们被要求输入并确认新密码。

页面的url是这样的:

/users/reset_password_confirm/23f9a5d7d1a2c952c01afacbefaba41a26062b17

视图是这样的:

<?php echo $form->create('User', array('action' => 'reset_password_confirm')); ?>
<?php 
    echo $form->input('password', array('label' => 'Password'));
    echo $form->input('confirm_password', array('type' => 'password', 'label' => 'Confirm password'));
    echo $form->hidden('static_hash');
?>
<?php echo $form->end('Reset password'); ?>

但是,这会产生如下形式:

<form id="UserResetPasswordConfirmForm" method="post" action="/users/reset_password_confirm/8">

问题是用户 ID(在本例中为 8)被添加到表单操作中。这不是一个真正的问题,但是当我想将哈希传递给我的控制器时:

function reset_password_confirm($static_hash=null) {
    // function body
}

$static_hash现在填充 8 而不是来自 URL 的哈希。

我知道我可以通过自己创建表单标签而不是使用来解决这个问题,$form->create但是有没有更简单的方法呢?

4

2 回答 2

1
$form->create('User', array('action' => '…', 'id' => false));

只需明确设置您不想传递给nullor的参数false。不幸的是,蛋糕为了自己的利益而试图变得有点过于聪明。;o)

您可能还可以执行以下操作以再次 POST 到相同的 URL:

$form->create('User', $this->here);
于 2010-02-16T13:58:48.317 回答
0

如何将其作为参数而不是表单数据传递:

<?php
echo $form->create('User', array('action' => 'reset_password_confirm', $static_hash));
    echo $form->input('password', array('label' => 'Password'));
    echo $form->input('confirm_password', array('type' => 'password', 'label' => 'Confirm password'));
echo $form->end('Reset password');
?>

在控制器中:

function reset_password_confirm($static_hash = null) {

// Check if form is submitted
if (!empty($this->data)) {
  // if it submitted then do your logic
} else {
  $this->set('static_hash', $static_hash); // Else, pass the hash to the view, so it can be passed again when form is submitted
}

}

希望这有帮助:)

于 2010-02-16T17:56:55.693 回答