2013-07-08 106 views
0

我是cakephp的新手。为了安全更新,我要求用户输入他的出生日期。如果他输入正确的出生日期,我想向他展示包含他的安全问题和他的密码的其他表格。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文件?编辑= set_security。

如何在输入正确的出生日期时显示其他表格?

+0

是什么你的视图文件中的$ security_set意味着它包含什么? –

+0

谢谢您的回复。$ security_set表示用户是否已经设置了他的安全性。意思是他已经填写了安全表单并输入了他的安全问题。我已设置他的安全性并想要更新它。然后,如果他点击编辑时,首先显示他的出生日期。如果他输入正确的出生日期,那么他会显示另一个表格。我无法向他显示其他表格。 –

+0

更好的问题标题急需。你真的在问如何呈现不同的视图文件吗?你的代码通常看起来很奇怪。 – AD7six

回答

1

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

$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'); 
    } 
    } 
} 
+0

此链接可能会帮助您实现相同的目的:http://stackoverflow.com/questions/11711385/rendering-controller-to-a-different-view-in-cakephp –