CakePHP plugin with static pages (PagesController in Plugin)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

CakePHP plugin with static pages (PagesController in Plugin)

Vanja Dizdarević
See the title of the post? I went nearly mad searching for it!! So I made it SEO friendly for any brothers-in-pain...

Question: What is the "proper" way to serve static pages in a plugin?

My basic idea was: "Oh, I'll just create the file in 'app/Plugin/ContactManager/Views/Pages/introduction.ctp' and it should pop up in /contact_manager/pages/introduction or /pages/contact_manager/introduction"

Got:
Error: MyFancyBoxerShorts.PagesController could not be found.
Error: Create the class PagesController below in file: .....

But I don't feel like creating a duplicate class name

I even tried
//file: PluginName/Controller/PagesController.php
require_once(ROOT . DS . APP_DIR . DS . 'Controller' . DS . 'PagesController.php');

But this fails, because the magic of Pages routing doesn't apply for plugins.

So, I have 2 possible solutions:

A: Create a PagesController inside my Plugin
- CON: duplicates class name
- CON: Any PagesController overrides from the user's app are lost (like layouts, helpers, markup parsers, tweaks)
- CON: requires plugin routing to achieve default pages/* (action: display) functionality

B: Add the pages routing to plugin routes.php (more conventional)
Create PluginName/PagesController.php // require_once(ROOT . DS . APP_DIR . DS . 'Controller' . DS . 'PagesController.php');
Add ONE of these in the routes.php
Router::connect('/:plugin/pages/*', array('controller' => 'pages', 'action' => 'display')); // potentially unsafe if other plugins define the same
Router::connect('/contact_manager/pages/*', array('controller' => 'pages', 'action' => 'display', 'plugin' => 'ContactManager')); //the "suitable solution"
Require the user to load routes with the Plugin.


While writing this, I have found the "suitable solution" (again), but I will leave it here in case anyone ever searches for it.

And I would honestly like your input on the most conventional way of doing this seemingly default-ish routing behavior.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: CakePHP plugin with static pages (PagesController in Plugin)

Fabricio Camarano
I know this is quite old, but I'm facing the same issue and google results brought me here.. 
So, which one could you say is the most suitable solution?.. the most conventional as you pointed or A?

El sábado, 16 de marzo de 2013, 14:53:53 (UTC-3), Vanja Dizdarević escribió:
See the title of the post? I went nearly mad searching for it!! So I made it SEO friendly for any brothers-in-pain...

Question: What is the "proper" way to serve static pages in a plugin?

My basic idea was: "Oh, I'll just create the file in 'app/Plugin/ContactManager/Views/Pages/introduction.ctp' and it should pop up in /contact_manager/pages/introduction or /pages/contact_manager/introduction"

Got:
Error: MyFancyBoxerShorts.PagesController could not be found.
Error: Create the class PagesController below in file: .....

But I don't feel like creating a duplicate class name

I even tried
//file: PluginName/Controller/PagesController.php
require_once(ROOT . DS . APP_DIR . DS . 'Controller' . DS . 'PagesController.php');

But this fails, because the magic of Pages routing doesn't apply for plugins.

So, I have 2 possible solutions:

A: Create a PagesController inside my Plugin
- CON: duplicates class name
- CON: Any PagesController overrides from the user's app are lost (like layouts, helpers, markup parsers, tweaks)
- CON: requires plugin routing to achieve default pages/* (action: display) functionality

B: Add the pages routing to plugin routes.php (more conventional)
Create PluginName/PagesController.php // require_once(ROOT . DS . APP_DIR . DS . 'Controller' . DS . 'PagesController.php');
Add ONE of these in the routes.php
Router::connect('/:plugin/pages/*', array('controller' => 'pages', 'action' => 'display')); // potentially unsafe if other plugins define the same
Router::connect('/contact_manager/pages/*', array('controller' => 'pages', 'action' => 'display', 'plugin' => 'ContactManager')); //the "suitable solution"
Require the user to load routes with the Plugin.


While writing this, I have found the "suitable solution" (again), but I will leave it here in case anyone ever searches for it.

And I would honestly like your input on the most conventional way of doing this seemingly default-ish routing behavior.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.