Hi, I m new to cakephp... I m developing an app using CakePhp and Mysql. In Cakephp i am having two tables one is Form (id ,name,created , modified) and attributes (id, Attribute-name ,form_id ,value) I kept everything in only one controller that is in forms controller.Within this formsctrller , i m having actions like login ,register,viewforms...
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...
Edit
<?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 Now i am using two controllers One for Users and One for Forms . But One Doubt .I have run the above code..Actually in my /forms/index.ctp
<?php
echo $javascript->link('prototype.js');
echo $javascript->link('scriptaculous.js');
echo $html->css('main.css');
?>
formBuildr
Register
<?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>
I have registered and login ..It goes /forms/homepage But the thing is that ..It doesn't show me the Flash message Of (Login successfull/Unsucessfull) I tried with render option , but even showing me the error.. Note :Since i no need to have anything in my views/users/login.ctp i am not having login.ctp..(SINCE I M LOGIN IN AND DIRECTLY MOVES TO HE HOMEPAGE OF MY FORMSCONTROLLER.