Cakephp は初めてです... CakePhp と Mysql を使用してアプリを開発しています。Cakephp には、フォーム (id、name、created、modified) と属性 (id、Attribute-name、form_id、value) の 2 つのテーブルがあります。ログイン、登録、ビューフォームなどのアクションを持つ...
Do i need to create a separate controller for login and register..If so Actually i will run in my system with http://localhost/cake/forms where i am having the place to register and login ...If i had separate controller,then how can i make that to switch from forms to login controller on login....Explain me...
編集
<?php
class UsersController extends AppController
{
var $name = 'Users';
var $helpers=array('Html','Ajax','Javascript','Form');
var $components = array( 'RequestHandler','Email');
var $uses=array('Form','User','Attribute');
//Function for login
function login()
{
$email_id=$this->data['User']['email_id'];
$password=$this->data['User']['password'];
$login=$this->User->find('all');
$this->set('Forms',$this->Form->find('all'));
foreach($login as $form):
if($email_id==$form['User']['email_id'] && $password==$form['User']['password'])
{
$this->Session->setFlash('Login Successful');
// $this->render('forms/homepage');
$this->redirect('/forms/homepage');
break;
}
else
{
$this->Session->setFlash('Login UnSuccessful');
//$this->redirect('/forms/index');
}
endforeach;
}
//Function to register the user into Users Table.
function register()
{
$this->set('Forms',$this->Form->find('all'));
if (!empty($this->data))
{
if ($this->User->save($this->data))
{
$this->Session->setFlash('You have been registered.');
$this->set('register', $this->Form->find('all'));
//$this->render('homepage');
$this->redirect('/forms/homepage');
}
}
}
}
Ya 今、私は 2 つのコントローラーを使用しています。1 つはユーザー用、もう 1 つはフォーム用です。しかし、1つの疑いがあります.私は上記のコードを実行しました..実際には /forms/index.ctp で
<?php
echo $javascript->link('prototype.js');
echo $javascript->link('scriptaculous.js');
echo $html->css('main.css');
?>
フォームビルダー
登録
<?php
echo $form->create('User',array('action'=>'register'));
echo $form->input('User.name');
echo $form->input('User.email_id');
echo $form->input('User.password');
echo $form->end('Register');
?>
</div>
<div id="login">
<h3>Login</h3>
<?php
echo $form->create('User',array('action'=>'login'));
echo $form->input('User.email_id');
echo $form->input('User.password');
echo $form->end('Login');
?>
</div>
登録してログインしました.. /forms/homepage に移動しますが、問題は..Flashメッセージが表示されないということです..注:views/users/login.ctpに何も入れる必要がないので、login.ctpはありません..(ログインしてから、フォームコントローラーのホームページに直接移動します。