Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple modules in cakephp application

Tags:

php

cakephp

I need to prepare three separate modules in cakephp. one is admin, hotel admin, guest. These three will be different kind of users having same login screen but internal layout will be totally separated.

Can we have three separate folder structure for all of them like three app folder or we need to use the routing (as mentioned here ) for these users which will result mixed controllers and that will difficult to manipulate.

like image 798
phpian Avatar asked Aug 18 '26 02:08

phpian


2 Answers

You can create the modules as "plugins" and then they will have separate models, views, and controllers. The default routing for plugins is that they can be accessed through /plugin_name/controller_name/action. Plugins can even have layouts of their own etc. The main application in your case would be reduced to authenticating users and checking permissions.

More info:
1.3: http://book.cakephp.org/1.3/en/view/1111/Plugins
2.0: http://book.cakephp.org/2.0/en/plugins.html

I would use routing only if the three modules had basically the same controllers and models.

like image 56
Joni Avatar answered Aug 19 '26 15:08

Joni


Combining prefix routing with multiple layouts should solve your problem. As Joep mentioned in the comments, the actions in your controllers follow a simple naming scheme admin_index(), hotel_admin_index() and guest_index() which makes it easy to organise your code.

You could use the following code in your AppController to handle switching between layouts (i.e. default.ctp, admin.ctp, and hotel_admin.ctp).

function beforeRender() {
  if (isset($this->params['prefix']) { 
    if ($this->params['prefix'] == 'admin') {
      $this->layout = 'admin';
    } else if ($this->params['prefix'] == 'hotel_admin')
      $this->layout = 'hotel_admin';
    }
  }
}

You can even take it a step further and separate all the static resources (i.e. /img/admin/new-blah.png)

like image 45
Lawrence Barsanti Avatar answered Aug 19 '26 15:08

Lawrence Barsanti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!