Category Archives: CakePHP


Using Cake Bake Console with both CakePHP 2.x and 3.x


I got started with my new CakePHP 3.x project today. As usual I wanted to create a few scaffold using cake bake command. As I already had a CakePHP 2.x setup in my machine. I still needed it and its cake bake commands to run to create any thing while working on the cakephp 2.x project. So is there a way I could use both cake bake consoles for CakePHP 2.x and 3.x respectively, at the same time?

Answer is YES. All we need to do is make some tweaks in order to run them both. Here are what I did.

  • I actually went back into the CakePHP 2.x installation and renamed the cake and cake.bat to cake2 and cake2.bat respectively. There are located in  C:\wamp\www\mycakephp2app\lib\Cake\Console.
  • This step actually was to set path environmental variable manually for CakePHP 3 as I already had set it up for CakePHP 2.x on my windows machine. I actually need them both. So I would add them like this C:\wamp\www\mycakephp2app\bin;C:\wamp\www\mycakephp2app\lib\Cake\Console;(for cakephp 3 it is set automatically.

    If you installed Cakephp 2 after CakePHP was installed you have to set the environmental variable path accordingly)

  • As you might have noticed that I renamed cake and cake.bat shell scripts to cake2 and cake2.bat  respectively I need to run cake2 bake in order to invoke CakePHP baker.


How to set Cakephp paginator url for custom Route

I was making a url route like this:

Router::connect('/ca/assets', array('plugin' => 'file_manager', 'controller' => 'file_manager', 'action' => 'assets', 'ca'));

It worked alright with normal urls as- /ca/assets. However when i used paginator in view as

echo $this->Paginator->numbers();

it generates url as- /assets/ca/page:2

I tried different things and at the end, as a work around to this problem I figured out that the following trick works. So make some heck in the $this->Paginator->options() function as the following:

'url'=>array('controller' => 'ca', 'controller'=>'action', 'plugin'=>false)