URL rewriting for plug-ins

edited April 2013 in Customizations
Hello guys,
I'm writing my first big plug-in, a contest system.
I have three .php files in the plug-in directory (HOST/cc-content/plugins/myplugin/):
1 - the plug-in file (install, uninstall and some hooks)
2 - a php class representing a contest (similar to the classes contained in cc-core/lib)
3 - a controller for the contest system (similar to the classes contained in cc-core/controllers)
The controller calls a .tpl file stored in the theme directory.

Is this the right way to structure a plug-in? I tried to respect as much as possible the architecture provided by the CumulusClips developers. I would like to be sure this is the correct way to proceede, because I'm planning to follow along as a plug-in developer. ;)

Next question... to reach the controller (and the relative page) I must link HOST/cc-content/plugins/myplugin/myplugincontroller.php
How do I make it possible to reach the page with HOST/myplugincontroller ? (similarly to HOST/members/).

Should I modify the .htaccess file? I prefer not for two reasons:
1 - don't know the syntax for .htaccess files
2 - the next update of cumulus will delete the .htaccess file
Is there another way around?? If there is not yet a system I would suggest to use something like HOST/plugins/myplugin/


  • edited April 2013
    Your described architecture for your plugin sounds good.

    As far as routing to your plugin, you have 3 options

    1) Direct - ie. http://domain.com/cc-content/plugins/yourplugin/controller.php
    2) Add an .htaccess rule - ie. RewriteRule ^custom/$ cc-content/plugins/yourplugin/controller.php [NC,L]
    3) Page System

    I think the current plugin system is a little weak for routing and creating pages. We will be addressing this routing problem in v2. The best way, in my opinion, to achieve what you're after is to create a 'Page' in the database. This will provide you with a pretty URL you can customize. Then attach to the plugin hook - page.before_render - and inject your custom content using something like:

    View::$vars->page->content = 'Your custom HTML';

    Otherwise, if you opt for option 1 or 2, listed above, you'll have to place the tpl file in the themes directory and either link directly to the controller file or create an .htaccess rule.
  • Thank you.
    I will keep the direct URL and wait for the 'official' way of doing this.
    The problem I'm having right now is with the Pagination... how can I make it work in my custom controller without having the URL rewriting?

    is not working. Can I use pagination with standard $_GET values? Like

  • You should be able to use $_GET variables. The only issue is that if you use our Pagination class then the generated links will want to use the URL rewrite rules.

    If you use your own pagination, there should be no issue using $_GET variables.
This discussion has been closed.