Created
May 27, 2011 13:18
-
-
Save hiromi2424/995223 to your computer and use it in GitHub Desktop.
MultiSlugRoute design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Report extends AppModel { | |
// set true when type => daily was affected | |
private $__dailyReportAffected = false; | |
/* | |
some implemetations... | |
*/ | |
function _clearCache($type = null) { | |
if ($this->__dailyReportAffected) { | |
MultiSlugRoute::clearCache('DailyReport'); | |
$this->__dailyReportAffected = false; | |
} | |
parent::__clearCache($type); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Router::connect( | |
'/report/daily/:username/:title/:written_date', | |
array( | |
'controller' => 'reports', | |
'action' => 'daily', | |
), | |
array( | |
'routeClass' => 'MultiSlugRoute', | |
'slugs' = array( | |
// uses username for slug and display | |
'username' => array( | |
'model' => 'User', | |
), | |
'title', | |
'written_date' => array( | |
// manually specify | |
'model' => 'DailyReport', // common model(Report) by default | |
'display' => 'written_date', // field name to show, slug(key of slugs array) by default | |
'urlencode' => false, | |
// give functions when you want to change slug from field value | |
'callbacks' => array( | |
// converting | |
'parse' => function($slug) { | |
return str_replace('-', '.', $param); | |
}, | |
// reversing | |
'match' => function($param) { | |
return str_replace('.', '-', $param); | |
}, | |
), | |
), | |
), | |
/* options */ | |
'model' => 'Report', // default, inflected from controller name | |
'cacheConfig' => 'slugs', // 'default' by default | |
'identity' => 'DailyReport', // :alias(Model::$alias) by default, useful for cache control | |
'urlencode' => true, // default, perhaps required whenever | |
'conditions' => array( | |
'type' => 'daily', | |
), // empty array by default | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment