change placeholder text from array - yii

I'm using the yii-user extension and i'm trying the add proper label to the 'placeholder' attribute. really new to Yii so still trying to get the grasp of things.
I've added the attributeLabels() method in the class in the models folder.
class RegistrationForm extends User {
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'email'=>'Email Address',
'firstname'=>'First Name',
'lastname' => 'Last Name',
'verifyPassword' = 'Retype Password'
);
}
}
Here is my code in my /views/ folder
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'registration-form',
'type'=>'vertical',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => 'email')); ?>
<?php echo $form->passwordField($model,'password', array('class' => 'input-block-level', 'placeholder' => 'password')); ?>
<?php echo $form->passwordField($model,'verifyPassword', array('class' => 'input-block-level', 'placeholder' => 'verifyPassword')); ?>
<?php
$profileFields=Profile::getFields();
if ($profileFields) {
foreach($profileFields as $field) {
if ($widgetEdit = $field->widgetEdit($profile)) {
//echo $widgetEdit;
} elseif ($field->range) {
echo $form->dropDownList($profile,$field->varname,Profile::range($field->range),array('class' => 'input-block-level'));
} elseif ($field->field_type=="TEXT") {
echo $form->textArea($profile,$field->varname,array('rows'=>6, 'cols'=>50));
} else {
//echo $field->varname;
if ($field->varname == 'firstname')
{
$placeholder = 'First Name';
}
else if ($field->varname == 'lastname')
{
$placeholder = 'Last Name';
}
else
{
$placeholder = $field->varname;
}
echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255),'class' => 'input-block-level', 'placeholder' => $placeholder));
}
echo $form->error($profile,$field->varname);
}
}
?>
how would i make attributeLabels() work on my echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255),'class' => 'input-block-level', 'placeholder' => $placeholder)); ?

You can get the text label for the specified attribute with getAttributeLabel() like:
$model->getAttributeLabel('verifyPassword');
E.x:
<?php echo $form->passwordField($model,'verifyPassword',
array('class' => 'input-block-level',
'placeholder' => $model->getAttributeLabel('verifyPassword')));
?>

you don't have to edit class RegistrationForm extends User
open protected/modules/user/model/User.php
add add/edit your custom labels in the attributeLabels() method
public function attributeLabels()
{
return array(
'id' => UserModule::t("Id"),
'username'=>UserModule::t("username"),
'password'=>UserModule::t("Password"),
'verifyPassword'=>UserModule::t("Retype Password"),
'firstname'=>UserModule::t("First Name"), //ADDED
'lastname'=>UserModule::t("Last Name"), // ADDED
'email'=>UserModule::t("Email Address"), //EDITED
'verifyCode'=>UserModule::t("Verification Code"),
'activkey' => UserModule::t("Activation Key"),
'createtime' => UserModule::t("Registration Date"),
'create_at' => UserModule::t("Registration Date"),
'lastvisit_at' => UserModule::t("Last Visit"),
'superuser' => UserModule::t("Superuser"),
'status' => UserModule::t("Status"),
);
}
and to get the label to show in your view file. use this
<?php echo $form->passwordField($model,'verifyPassword',
array('class' => 'input-block-level',
'placeholder' => $model->getAttributeLabel('email')));
?>

Related

Yii2: Images stored in different tables

Here my controller:
$model = new VehicleType();
if ($model->load(Yii::$app->request->post())) {
if($model->validate()){
$model->save();
$id = $model->id;
$model->file = UploadedFile::getInstance($model, 'file');
if($model->file){
$id = $model->id;
$imageName = "vehicletype_".$id.'_'.getdate()[0];
$model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
$station = VehicleType::findOne($id);
$station->image = '#web/uploads/'.$imageName.'.'.$model->file->extension;
$station->save();
}
return $this->redirect(['vehicletype/index']);
}
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
My view:
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'station-form', 'options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'description')->textarea() ?>
<?= $form->field($model, 'file')->fileInput() ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
My model:
public function rules()
{
return [
[['description'], 'string'],
[['record_status'], 'integer'],
[['name', 'image'], 'string', 'max' => 255]
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'image' => 'Image',
'record_status' => 'Record Status',
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getVehicles()
{
return $this->hasMany(Vehicles::className(), ['vehicle_type_id' => 'id']);
}
}
With this I can upload only one picture/post, I want one post to have multiple pictures, so I create a new table call 'Image' to stored my pictures and have a one-to-many relationship.
But I run into a problem, how can I add data to 2 tables from just 1 form
I'm using Yii2 basic template
Thanks
Step 1
First create two variables in your vehicletype model.
public $uploadedImages;
public $imageforNewtable = array();
Step 2
Make sure to mention this imageforNewtable variable in your model rule.
[['imageforNewtable'], 'image', 'extensions' => 'png, jpg, JPEG'],
Step 3
In your form:
<?php $form = ActiveForm::begin(['id' => 'station-form', 'options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'imageforNewtable[]')->fileInput(['accept' => 'image/*']); ?>
Step 4
In Your Controller:
$model->uploadedImages = UploadedFile::getInstances($model,'imageforNewtable');
// Make sure to put "Instances" (plural of Instance) for uploading multiple images
$model->imageforNewtable = array(); // To avoid blank entries as we have entries in $_FILES not in $_POST.
foreach ($model->uploadedImages as $singleImage)
{
$model->imageforNewtable[] = time() . '_' . $singleImage->name;
}
Now bulk insert data in Images table :
$bulkInsertforimages = array(); //defined benchInsert array for images
$columnsArray = ['blog_id', 'image']; //Column names in which bulk insert will take place.
if ($model->imageforNewtable != '') {
foreach ($model->imageforNewtable as $singleData) {
$bulkInsertforimages[] = [
'blog_id' => $model->id,
'image' => $singleData,
];
}
}
if (count($bulkInsertforimages) > 0) {
$command = \Yii::$app->db->createCommand();
$command->batchInsert('YOUR_IMAGE_TABLE', $columnsArray, $bulkInsertforimages)->execute();
}

File Not uploading in yii2

I want to upload an image and save it into my database.
Here, the field name in database is image_path. When, I am trying to upload my image it shows an error: Call to a member function saveAs() on a non-object on line
$customer->file->saveAs('uploads/customer/' . $customer->file->baseName . '.' . $customer->file->extension);
If I print var_dump($customer->file); it returns NULL.
Can anyone help me to resolve this issue.
This is my view:
<?php $form = ActiveForm::begin([
'id' => 'my-profile',
'action' => \Yii::$app->urlManager->createUrl(['/myprofile', 'id_customer' => Yii::$app->user->identity->id_customer]),
'options' => ['enctype'=>'multipart/form-data']
]); ?>
<?= $form->field($customer, 'file')->fileInput() ?>
<?php ActiveForm::end(); ?>
This is my Model:
public $file;
public function rules()
{
return [
['active', 'default', 'value' => self::STATUS_ACTIVE],
['active', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
[['file'],'file'],
[['name', 'image_path'], 'string', 'max' => 200],
];
}
public function attributeLabels()
{
return [
'file' => 'Profile Picture ',
];
}
This is my controller:
public function actionMyprofile(){
$customer->file = UploadedFile::getInstance($customer,'image_path');
$customer->file->saveAs('uploads/customer/' . $customer->file->baseName . '.' . $customer->file->extension);
$customer->file = 'uploads/customer/' . $customer->file->baseName . '.' . $customer->file->extension;
}
View:
<?php $form = ActiveForm::begin([
'id' => 'my-profile',
'action' => \Yii::$app->urlManager->createUrl(['/myprofile', 'id_customer' => Yii::$app->user->identity->id_customer]),
'options' => ['enctype'=>'multipart/form-data']
]); ?>
<?= $form->field($customer, 'image_path')->fileInput() ?>
<?php ActiveForm::end(); ?>
Model:
public function rules()
{
return [
['active', 'default', 'value' => self::STATUS_ACTIVE],
['active', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
[['image_path'],'file'],
[['name', 'image_path'], 'string', 'max' => 200],
];
}
public function attributeLabels()
{
return [
'image_path' => 'Profile Picture ',
];
}
Controller:
public function actionCreate()
{
$model = new YourModel_name();
if ($model->load(Yii::$app->request->post())) {
$model->image_path = UploadedFile::getInstance($model, 'image_path');
$filename = pathinfo($model->image_path , PATHINFO_FILENAME);
$ext = pathinfo($model->image_path , PATHINFO_EXTENSION);
$newFname = $filename.'.'.$ext;
$path=Yii::getAlias('#webroot').'/image/event-picture/';
if(!empty($newFname)){
$model->image_path->saveAs($path.$newFname);
$model->image_path = $newFname;
if($model->save()){
return $this->redirect(['your redirect_path', 'id' => $model->id]);
}
}
}
return $this->render('create', [
'model' => $model,
]);
}

registration form post field as empty

i'm using Yii-user, and have made some modification to the user/views/user/registration.php file.
for some reason even when i fill in firstname and lastname, it still says i left those fields empty. any idea why?
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'registration-form',
'type'=>'vertical',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('email'))); ?>
<?php echo $form->passwordField($model,'password', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('password'))); ?>
<?php echo $form->passwordField($model,'verifyPassword', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('verifyPassword'))); ?>
<p class="text-seperator"> about you </p>
<?php echo $form->textField($profile,'firstname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('firstname'), 'maxlength'=> 255)); ?>
<?php echo $form->textField($profile,'lastname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('lastname'), 'maxlength'=> 255)); ?>
and in my user/models/registrationform.php i have this
class RegistrationForm extends User {
public $firstname; //added
public $lastname; //added
public $verifyPassword;
public $verifyCode;
public function rules() {
$rules = array(
array('firstname, lastname, password, verifyPassword, email', 'required'),
array('firstname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect First Name (length between 3 and 225 characters).")),
array('lastname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect Last Name (length between 3 and 225 characters).")),
.........
}
}
to fill up firstname and last name using the original code they used this...
$profileFields=Profile::getFields();
if ($profileFields) {
foreach($profileFields as $field) {
?>
<!--div class="row"-->
<?php echo $form->labelEx($profile,$field->varname); ?>
<?php
if ($widgetEdit = $field->widgetEdit($profile)) {
echo $widgetEdit;
} elseif ($field->range) {
echo $form->dropDownList($profile,$field->varname,Profile::range($field->range));
} elseif ($field->field_type=="TEXT") {
echo$form->textArea($profile,$field->varname,array('rows'=>6, 'cols'=>50));
} else {
echo $field->varname.'<br />';
echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255)));
}
?>
<?php echo $form->error($profile,$field->varname); ?>
<!--/div-->
<?php
}
}
I think you need to change this,
you have passed $model in here:
<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('email'))); ?>
but you have given $profile here:
<?php echo $form->textField($profile,'firstname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('firstname'), 'maxlength'=> 255)); ?>
if you check out the generated html, you will notice that the generated input has different name!
i'm not sure why this works (would be great is someone could explain in detail)
but the issue was here..
public function rules() {
$rules = array(
array('firstname, lastname, password, verifyPassword, email', 'required'),
array('firstname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect First Name (length between 3 and 225 characters).")),
array('lastname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect Last Name (length between 3 and 225 characters).")),
.........
}
}
firstname, lastname when this is removed it works. and it still is set as required.

Yii framework CMultifileupload not working

I'm trying to implement a multiple file upload using CMultiFileUpload with CUploadedFile, but it doesn't work. Specifically, _POST is not working even considering that I'm using 'enctype' => 'multipart/form-data' in the options in the view:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'examen-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
and this is the widget and parameters used for CMultiFileUpload:
<div class="row">
<?php echo $form->labelEx($model,'archivo_foto')?>
<?php //echo CHtml::activeFileField($model,'archivo_foto')?>
<?php $this->widget('CMultiFileUpload', array(
'model' => $model,
'name' => 'archivo_foto',
'accept' => 'jpeg|jpg|gif|png|txt', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
'max' => 10,
'htmlOptions' => array( 'multiple' => 'multiple', 'size' => 25 ),
)); ?>
<?php echo $form->error($model,'archivo_foto')?>
</div>
On the other hand, the controller action is implemented this way:
public function actionUpdateam($id)
{
$model=$this->loadModel($id);
$dir=Yii::getPathOfAlias('application.uploads');
$model->archivo_documento='funciona 0';
if(isset($_POST['Examen'])) {
$model->attributes=$_POST['Examen'];
// THIS is how you capture those uploaded images: remember that in your CMultiFile widget, you set 'name' => 'archivo_foto'
$images = CUploadedFile::getInstancesByName('archivo_foto');
// proceed if the images have been set
$model->archivo_documento='funciona uno';
if (isset($images) && count($images) > 0) {
$model->archivo_documento='funciona dos';
// go through each uploaded image
foreach ($images as $image) {
echo $image->name.'<br />';
$image->saveAs($dir.'/'.$image->name);
$model->archivo_foto = $model->archivo_foto."+".$image->name;
}
// save the rest of your information from the form
if ($model->save()) {
$this->redirect(array('view','id'=>$model->id));
}
}
}
$this->render('update_am',array(
'model'=>$model,
));
}
And at last, I think that is important to mention the rule used for the model (it might be the cause of the problem as well):
array('archivo_foto','file','allowEmpty'=>true,'maxFiles'=>10),
I think that the problem is in post method, because the controller is not uploading the files and is not making any changes in the database. But I'm not sure.
Try changing to 'htmlOptions'=>array('multiple'=>true).
Add following code in the Form
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
Like
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>true,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
I am using the same extension and it is wokring for me with these codes
In the view file
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'adpost-form',
'enableClientValidation'=>true,
'clientOptions' => array(
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'afterValidate'=>'js:submiAjaxForm'
),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'photo_name',
'accept' => 'jpeg|jpg|gif|png',
'duplicate' => 'File is not existed!',
'denied' => 'Not images', // useful,
'htmlOptions' => array(
'style' =>'color: transparent;',
),
));
?>
And in the contoller
$images = CUploadedFile::getInstancesByName('photo_name');
foreach ($images as $image => $pic) {
//----------------- Renaming image before uploading
$extension = $pic->getExtensionName();
$newName = "image_".$adModel->id;
$newName .= "_".$imgCount.".".$extension;
$imgCount++;
if ($pic->saveAs($newPath.$newName)) {
// add it to the main model now
$img_add = new AdsPhotosTbl;
$img_add->photo_name = $newName;
$img_add->ad_id = $adModel->id;
$img_add->status = 1;
if(!$img_add->save()){
$error = true;
$upload_error = true;
break;
}
}else{
$upload_error = true;
$error = true;
break;
}
}

Strange CakePHP 2.0 auth login issue

Ok, so I was having a very interesting issue with CakePHP 1.3, in that even if I used the correct information to try to log in, it wouldn't work. I've now upgraded the same app to Cakephp 2.0, and I'm having a very different issue. Basically now, regardless of what information I put in when I'm logging in, it will log in. Even if the database is empty. No idea why this is happening...
Here's my code:
View:
<div id="login">
<p>Please log in! <a id="register" href="register" alt="Register">Register</a></p>
<hr class="login"/>
<?php
echo $this->Session->flash('auth');
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo "<hr class=\"login\"/>";
echo $this->Form->end('Login');
echo $this->Session->flash('flash_registration');
echo "<pre>"; print_r($this->request->data); echo "</pre>";
echo $this->Html->link('Log-Out', 'logout');
?>
</div>
Model:
<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
var $name = 'User';
var $validate = array(
'name' => array(
'custom_rule' => array(
'rule' => '/^[A-Za-z\s]*$/i',
'message' => 'Please enter an acceptable name'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
),
'dob' => array(
'rule' => array('date', 'ymd'),
'message' => 'Enter a valid date',
),
'phone' => array(
'numbers' => array(
'rule' => 'numeric',
'message' => 'Numbers only, no dashes or spaces'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
),
'username' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'message' => 'Letters and numbers only'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
),
'e-mail' => array(
'email' => array(
'rule' => 'email',
'message' => 'Please enter a valid e-mail address'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
),
'password_enter' => array(
'length' => array(
'rule' => array('between', 8, 16),
'message' => 'Password must be between 8 and 16 characters'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
),
'password_confirm' => array(
'identicalFieldValues' => array(
'rule' => array('identicalFieldValues', 'password_enter'),
'message' => 'Passwords do not match'
),
'length' => array(
'rule' => array('between', 8, 16),
'message' => 'Password must be between 8 and 16 characters'
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'This field is required'
)
)
);
function identicalFieldValues( $field=array(), $compare_field=null ){
foreach( $field as $key => $value ){
$v1 = $value;
$v2 = $this->data[$this->name][ $compare_field ];
if($v1 !== $v2) {
return FALSE;
} else {
return TRUE;
}
}
}
function beforeValidate(){
$this->data['User']['dob'] = $this->data['User']['dob'];
return true;
}
function beforeSave(){
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password_enter']);
$this->data['User']['activated'] = FALSE;
return TRUE;
}
}
?>
Controller:
<?php
class UsersController extends AppController {
var $name = 'Users';
var $uses = array("User");
var $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pages', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
)
);
var $helpers = array('Form', 'Session', 'Html');
function beforeFilter(){
// Basic setup
$this->Auth->authenticate = array('Form');
$this->Auth->allow('register', 'activate');
}
function index() {
}
function login() {
$this->Auth->login($this->request->data);
$this->set('title_for_layout', "Welcome to Sound-On.com!");
$this->layout = 'user_functions';
if ($this->Auth->user()) {
echo "Logged in!";
} else {
echo "Not logged in!";
}
}
function logout() {
$this->redirect($this->Auth->logout());
}
function register(){
$this->set('title_for_layout', "Register Here!");
$this->layout = 'user_functions';
$date = date('Y');
if (!empty($this->data)) {
$user_check = $this->User->find('first', array('conditions' => array('username' => $this->data['User']['username'])));
$email_check = $this->User->find('first', array('conditions' => array('e-mail' => $this->data['User']['e-mail'])));
if (empty($user_check)) {
if(empty($email_check)){
if ($this->User->save($this->data)) {
$uuid_string = $this->data['User']['activation_hash'];
$email = <<<EOT
<html>
<head>
<title>Welcome to Sound-On.com!</title>
</head>
<body>
<p>
<h1>Welcome to Sound-on.com!</h1>
<p>You have successfully registered! To activate your account and start sounding on, please click Here! <br/>If the link is not clickable, please copy and paste the link below into your browser address bar.</p>
http://www.sound-on.com/activate?uid=$uuid_string
<p style="">Thank you for registering!</p>
<p>Your friendly Sound-On registration robot</p>
<p>If you did not register or wish to remove your account, please click here.</p>
<p style="font-size:8pt;color:#707070">© Copyright $date Sound-on.com. All rights Reserved.</p>
</p>
</body
</html>
EOT;
$to = $this->data['User']['e-mail'];
$subject = 'Welcome to Sound-On.com!';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: registration#Sound-On.com';
if (mail($to, $subject, $email, $headers)) {
$this->redirect('/');
}
} else {
//$this->Session->setFlash('<p class="register_flash">Something went wrong. Please try again.</p>', 'flash_registration');
//$this->flash('', '/');
}
} else {
//email exists
}
} else {
//username exists
}
}
}
function activate(){
$this->set('title_for_layout', "Register Here!");
$this->layout = 'user_functions';
if (!empty($_GET)) {
$activate = $this->User->updateAll(array('activated' => 1), array('activation_hash' => $_GET['uuid']));
if ($activate) {
$this->set('message', '<p id="activation_message">Your account has been successfully activated! Please click here to proceed to login!</p>');
}
}
}
}
?>
Thanks in advance!
If you send data to the Auth->login() function it will log in with the data.
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in
You need to use something like this.
public function login() {
if ($this->request->is('post')) {
if (!$this->Auth->login()) {
$this->Session->setFlash('Your username or password was incorrect.');
} else {
$this->Session->setFlash('You are now logged in.');
//redirect
}
}
}