Category: CakePHP

cakephp 3 social login — Site Title


Here is the link for social login in cakephp3

https://github.com/ADmad/CakePHP-HybridAuth

Advertisements

Passing data from CakePHP component to a helper


Helpfull

Sourabh Jain

My query was :- Is there any elegant way to pass data from a component to a helper?
Yes, the same way you pass any data to the helper. In your view.
Inside your component I would do something like the following. The beforeRender() action is a CakePHP component callback.

publicfunction beforeRender(Controller $controller){
    $yourVars ='some data';
    $goHere ='other stuff';

    $controller->set(compact('yourVars','goHere'));}

Then in your view you can pass the data off to your helpers just like normal.

// view or layout *.ctp file
$this->YourHelper->yourMethod($yourVars);
$this->YourHelper->otherMethod($goHere);

View original post

How to paginate multiple results in CakePHP?


Nice

For Latest Tech Updates Go To http://www.techstazo.com

Sourabh Jain

Here is my solution. In your controller :

function index(){// Your default model
    $this->set('model1', $this->paginate());// Pagination for model2
    $this->set('model2', $this->paginate('Model2'));}

In your view :

// Display your model1 data, and then for prev and next 
echo $paginator->prev($options = array('model'=>'Model1'));
echo $paginator->next($options = array('model'=>'Model1'));
The point is input your model name to Controller's paginate method and to Paginator's link method (sort, prev, next).

// Display your model2 data, and then for prev and next 
echo $paginator->prev($options = array('model'=>'Model2'));
echo $paginator->next($options = array('model'=>'Model2'));

View original post

Page borders in all pages Using TCPDF


You can add borders to all pages in pdf generated using TCPDF by simple two steps.

  • Create a new class extend from TCPDF class
  • Override the Header method. (Header method is called on a generation of each new page in TCPDF)
<?php
App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','tcpdf/config/lang/eng');
class PTCPDF extends TCPDF
{
     protected $processId =0;
     protected $header ='';
     protected $footer ='';
     static $errorMsg ='';
    /**
      * This method is used to override the parent class method.
      **/
     public function Header()
     {
          $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);

          $this->SetLineStyle( array('width'=>0.40,'color'=> array(0,0,0)));

          $this->Line(5,5, $this->getPageWidth()-5,5); 

          $this->Line($this->getPageWidth()-5,5, $this->getPageWidth()-5,  $this->getPageHeight()-5);
          $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
          $this->Line(5,5,5, $this->getPageHeight()-5);
     }
}

For Latest Tech Updates Go To www.techstazo.com

Retrieve Data By Multiple Order Priority In CakePHP


How you cab retrieve data from database by multiple field order priority………?

In cakePHP you can do easily as shown in below example.

In the following pagination query will output as Model first_name in Ascending order and Model last_name in Descending order.

 
$this->paginate = array(
        'conditions' => array(
                        ‘Model.created_date <‘  =>  ‘2014-01-01’
        ),
        'order' => array(
            'Model.first_name'  => 'ASC',
            'Model.last_name'  => 'DESC',
        ),
);
 
$this->set('data'$this->paginate('Model'));