SpamBlocker
Spam Blocker is a CakePHP Behavior that automatically before after a comment is made. Each comment is tested upon a point system to determine if it should be approved, set to pending (high points), or marked as spam / deleted (low points).
Table of Contents
Version: 2.0
Requires: PHP 5.2, CakePHP 2.0
Tested On: PHP 5.3, CakePHP 2.0.3
Commit Hash: 7ee365820c
Released: Nov 22nd 2011, 23:46
Requires: PHP 5.2, CakePHP 2.0
Tested On: PHP 5.3, CakePHP 2.0.3
Commit Hash: 7ee365820c
Released: Nov 22nd 2011, 23:46
RedirectRoute
Version: 2.0 (logs)
Package: Route: Legacy Route Handler
Category: CakePHP
Views: 757
Permalink -
Tinylink
A basic route class that handles HTTP redirects for legacy URLs. Supports a simple before and after callback system to hook into the redirect cycle.
Class Features:
Class Features:
- Allows you to define redirectable URLs using Router::connect()
- URLs are redirected before the dispatcher begins and evades the overhead process
- Can pass specific status codes for each redirect: 301, 302, 303, 304, 305, 307
Top
1 - Installation
Add the route class to your Lib/Route folder and import the class in your config/routes.php.
Once imported, you will use the Router::connect() method to setup your route.
App::import('Lib', 'Route/RedirectRoute');
Once imported, you will use the Router::connect() method to setup your route.
Top
2 - Usage
The first and second arguments will be the old URL respectively (in CakePHP format). The third argument will be an array of options; the following values are accepted: routeClass, redirect, status (optional, defaults to 301), after (optional), before (optional). The routeClass option is required and should be set to RedirectRoute. The redirect option will be an array of controller and action values, or a literal URL string. The status option will be the HTTP status code (301, 302, 303, 304, 305, 307). Read below for information on the before and after callbacks.
Below are a few examples on redirecting pages:
Below are a few examples on redirecting pages:
// Redirect /users/login/ to /account/login/ Router::connect('/users/login/*', array('controller' => 'users', 'action' => 'login'), array( 'routeClass' => 'RedirectRoute', 'redirect' => array('controller' => 'account', 'action' => 'login'), 'status' => 307 )); // Redirect /blog/archives/tags/ to /blog/tags/ Router::connect('/blog/archives/tags/*', array('controller' => 'blog', 'action' => 'archives', 'tags'), array( 'routeClass' => 'RedirectRoute', 'redirect' => array('controller' => 'blog', 'action' => 'tags') ));
Top
3 - Before and After Callbacks
If you are running PHP 5.3 you can use a Closure to define before and after callbacks (the first argument will be the route object). If you are not running 5.3, you can create a new class that extends RedirectRoute and overwrite the before() and after() methods.
Router::connect('/users/login/*', array('controller' => 'users', 'action' => 'login'), array( 'routeClass' => 'RedirectRoute', 'redirect' => array('controller' => 'account', 'action' => 'login'), 'status' => 307, 'before' => function($route) { $route->options['redirect'] = '/url'; }, 'after' => function($route) { header('X-Framework: CakePHP'); } ));
Top
Read the whole documentation? Download the script now and try it yourself! Return to the Top
4 - Passing Variables
Finally, if you need to pass dynamic variables, you simply write your connect() methods like before. Anything you define in the pass array will be replaced in the URL string. In the example below, the :tag string will be replaced with the value parsed from the URL.
Router::connect('/blog/archives/tags/:tag', array('controller' => 'blog', 'action' => 'archives', 'tags'), array( 'routeClass' => 'RedirectRoute', 'redirect' => array('controller' => 'blog', 'action' => 'tags', ':tag'), 'tag' => '[a-zA-Z0-9\-\_]+', 'pass' => array('tag') ));