Showing posts with label CakePhp. Show all posts
Showing posts with label CakePhp. Show all posts

Tuesday, 8 March 2016

How to change user password in CakePhp using Auth


cakephp.jpg

Hi All,
In this blog we will discuss how to change the password in cakePhp by using Auth.
Firstly, in your model you have to define a function beforeSave which will hash your password to auth password, you can do this by writing the below code:

  1. public function beforeSave($options = array()) {

  2.       if (isset($this->data[$this->alias]['password'])) {

  3.       $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
  4.       }
  5.       return true;
  6.   }
In your change Password function you have to write-
  1.   public function changePassword() {

  2.       if ($this->data) {
  3.           if (!empty($this->data['User']['password']) && !empty($this->data['User']['repassword'])) {
Read full blog about How to change user password in CakePhp using Auth visit Findnerd.

Wednesday, 29 April 2015

Simple Cakephp Pagination


Cakephp provides a quick an easy way to paginate data.
In the controller we start by creating the pagination condition as given below :
  1. public $paginate = array(
  2. 'limit' => 10,
  3. 'order' => array(
  4. 'Model.fieldname' => 'asc'
  5. )
  6. );
  7. public function listdetails(){
  8. $variable = $this->paginate("Model", array('Model.fieldname' =>'1'));
  9. }

Write the following code in the view where pagination has to be displayed here the view name is listdetails.ctp
  1. <?php
  2. echo $this->paginator->prev('<<Previous', null, null, null);
  3. echo $this->paginator->numbers();echo "&nbsp;|";
  4. echo $this->paginator->next('Next>>', null, null, null);
  5. ?>

For such more Blogs you can visit to http://findnerd.com/NerdDigest