Tuesday, September 4, 2012

Re: How to use two view(controller) in a page??

Actually, I can not see the login form that were written in login.ctp although I already use the requestAction().
The source code related the problem as below:

UsersController.php:
class UsersController extends AppController
{
        ....................................................
        ....................................................
        public function login()
{
if($this->request->is('post'))
{
$result = $this->User->findByUsernameAndPassword(
$this->data['User']['username'],
$this->data['User']['password']);
if($result)
{
$credential = Security::generateAuthKey();
//将凭据更新到数据库
$this->request->data['User']['credential'] = $credential;
$this->User->id = $result['User']['id'];
$this->User->save($this->request->data);
$this->Session->setFlash('登录认证成功');
//设置cookie
$this->Cookie->write('Users.username', $this->data['User']['username']);
$this->Cookie->write('Users.credential', $credential);
$this->redirect(array('action'=>'index'));
}
else
{
$this->Session->setFlash('登录认证失败');
}
}
}
        ....................................................
        ....................................................
}

login.ctp
<h1>login system</h1>
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('登录系统');
?>

home.ctp
<?php
  $result = $this->requestAction('/users/login');
  var_dump($result);
?>

The result of requestAction is null.
I am sure the login method in UsersController is called, because if I put 
       "return 1;" 
on the first line of login method, the return value of requestAction is 1.

the problem is why the requestAction does not load the login view to the homepage?

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: