Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Resource map accessor #391

Closed
wants to merge 2 commits into from

3 participants

@vesln

At this point there is no way to set custom resourceMap, without extending the Router. So, for example if you want the PUT /my-controller/:id to be pointed to MyController::update there is no easy way to do it. That's why I think that resourceMap accessor will be pretty useful.

@ceeram
Collaborator

How about using:

<?php
Router::connect(
    "/:controller/:id",
    array("action" => "update", "[method]" => "PUT"),
    array("id" => "[0-9]+")
);
?>

Also please dont target pull request against master, base bugfixes against current development branch, base new features against development branch for next version(2.1)

Personally i would like such thing, as i ran into the same thing just this week.

@vesln

It's definitely a good option. But my discomfort with that it will be global for all routes.

@markstory
Owner

Could you make the target branch for the pull request 2.1? We don't merge new features onto the master branch, as it always reflects the last stable release.

Other than that it looks like a reasonable change to me.

@vesln

Thank you @ceeram. The new pull request is here - #392

@vesln vesln closed this
@vesln

@markstory Sorry for that. I just sent a new pull request.

@vesln vesln referenced this pull request
Merged

Resource map #392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2012
  1. @vesln

    Adding resourceMap accessor

    vesln authored
  2. @vesln
This page is out of date. Refresh to see the latest.
View
14 lib/Cake/Routing/Router.php
@@ -175,6 +175,20 @@ public static function getNamedExpressions() {
}
/**
+ * Resource map getter & setter.
+ *
+ * @param array $resourceMap Resource map
+ * @return mixed
+ * @see Router::$_resourceMap
+ */
+ public static function resourceMap($resourceMap = null) {
+ if ($resourceMap === null) {
+ return self::$_resourceMap;
+ }
+ self::$_resourceMap = $resourceMap;
+ }
+
+/**
* Connects a new Route in the router.
*
* Routes are a way of connecting request urls to objects in your application. At their core routes
View
31 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -2455,6 +2455,37 @@ public function testPatternOnAction() {
}
/**
+ * Tests resourceMap as getter and setter.
+ *
+ * @return void
+ */
+ public function testResourceMap() {
+ $default = Router::resourceMap();
+ $exepcted = array(
+ array('action' => 'index', 'method' => 'GET', 'id' => false),
+ array('action' => 'view', 'method' => 'GET', 'id' => true),
+ array('action' => 'add', 'method' => 'POST', 'id' => false),
+ array('action' => 'edit', 'method' => 'PUT', 'id' => true),
+ array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
+ array('action' => 'edit', 'method' => 'POST', 'id' => true)
+ );
+ $this->assertEquals($default, $exepcted);
+
+ $custom = array(
+ array('action' => 'index', 'method' => 'GET', 'id' => false),
+ array('action' => 'view', 'method' => 'GET', 'id' => true),
+ array('action' => 'add', 'method' => 'POST', 'id' => false),
+ array('action' => 'edit', 'method' => 'PUT', 'id' => true),
+ array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
+ array('action' => 'update', 'method' => 'POST', 'id' => true)
+ );
+ Router::resourceMap($custom);
+ $this->assertEquals($custom, Router::resourceMap());
+
+ Router::resourceMap($default);
+ }
+
+/**
* test setting redirect routes
*
* @return void
Something went wrong with that request. Please try again.