繁体   English   中英

CakePhp需要帮助

[英]CakePhp help needed

我是cakephp的新手。 为了更新安全性,我要求用户输入他的出生日期。 如果他输入正确的出生日期,我想向他显示另一种形式,其中包含他的安全性问题以及他的密码。

有两种不同形式:一种是安全性检查(出生日期验证),另一种是设置安全性(安全性问题+密码)。

如果设置了安全性,则首先显示安全检查表,并要求输入他的生日。如果生日正确,则应显示设置的安全性表单,我无法这样做。

我的个人资料页面代码显示了这两种形式;

<?php if($_GET['edit'] == 'set_security'){ ?>
        <?php if (empty($security_set)): ?>
        <?= $this->element('../users/set_security') ?>
        <?php else:?>
         <?= $this->element('../users/set_security_check') ?>
        <?php endif; ?>
        <?php } ?>

我在conntroller中编写的功能是

function set_security_check()
{
   $user = $this->_authenticate_user();
   $id = $user['account_num'];
   $this->loadModel('UserProfile');
   $user_profile = $this->UserProfile->read(null, $id);
   $oldBirthdate = $user_profile['UserProfile']['birthday']; 
     if (!empty($this->data)) {
         $birthday = $this->data['UserProfile']['birthday'];
         if($oldBirthdate != $birthday)
         {
           $this->flashMessage(__('Your Birthday is Invalid. Please, try again.', true));

         }
         else
         {
          $this->flashMessage(__('Your Birthday Verified successfully', true), 'Sucmessage');
          $this->set('success', true);
         }

     }


}

当用户单击安全性编辑按钮时,我正在发送查询字符串/ profile?edit = set_security。

输入正确的出生日期后如何显示其他形式?

您可以在符合条件的控制器中使用以下代码简单地显示任何其他形式:

$this->render('/users/other_form');

如果我是正确的,那么您的代码应如下所示:

function set_security_check()
{
  $user = $this->_authenticate_user();
  $id = $user['account_num'];
  $this->loadModel('UserProfile');
  $user_profile = $this->UserProfile->read(null, $id);
  $oldBirthdate = $user_profile['UserProfile']['birthday']; 
  if (!empty($this->data)) {
     $birthday = $this->data['UserProfile']['birthday'];
     if($oldBirthdate != $birthday)
     {
       $this->flashMessage(__('Your Birthday is Invalid. Please, try again.', true));

     }
     else
     {
      $this->flashMessage(__('Your Birthday Verified successfully', true), 'Sucmessage');
      $this->set('success', true);
      $this->render('/controller_name/other_form');
     }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM