Skip to content
Permalink
Browse files

Fix form url generation for named route.

Fixes #4492
  • Loading branch information...
ADmad committed Sep 4, 2014
1 parent edf9187 commit 30f91686352695a2a13970459abda883a868f122
Showing with 40 additions and 21 deletions.
  1. +23 −21 src/View/Helper/FormHelper.php
  2. +17 −0 tests/TestCase/View/Helper/FormHelperTest.php
@@ -364,32 +364,34 @@ protected function _formUrl($context, $options) {
if ($options['action'] === null && $options['url'] === null) {
return $this->request->here(false);
}
if (empty($options['url']) || is_array($options['url'])) {
if (isset($options['action']) && empty($options['url']['action'])) {
$options['url']['action'] = $options['action'];
}
$plugin = $this->plugin ? Inflector::underscore($this->plugin) : null;
$actionDefaults = [
'plugin' => $plugin,
'controller' => Inflector::underscore($this->request->params['controller']),
'action' => $this->request->params['action'],
];
if (is_string($options['url']) ||
(is_array($options['url']) && isset($options['url']['_name']))
) {
return $options['url'];
}
if (isset($options['action']) && empty($options['url']['action'])) {
$options['url']['action'] = $options['action'];
}
$action = (array)$options['url'] + $actionDefaults;
$plugin = $this->plugin ? Inflector::underscore($this->plugin) : null;
$actionDefaults = [
'plugin' => $plugin,
'controller' => Inflector::underscore($this->request->params['controller']),
'action' => $this->request->params['action'],
];
$pk = $context->primaryKey();
if (count($pk)) {
$id = $context->val($pk[0]);
}
if (empty($action[0]) && isset($id)) {
$action[0] = $id;
}
return $action;
$action = (array)$options['url'] + $actionDefaults;
$pk = $context->primaryKey();
if (count($pk)) {
$id = $context->val($pk[0]);
}
if (is_string($options['url'])) {
return $options['url'];
if (empty($action[0]) && isset($id)) {
$action[0] = $id;
}
return $action;
}
/**
@@ -547,6 +547,23 @@ public function testCreateCustomRoute() {
'/div'
);
$this->assertHtml($expected, $result);
Router::connect(
'/new-article',
['controller' => 'articles', 'action' => 'myaction'],
['_name' => 'my-route']
);
$result = $this->Form->create(false, ['url' => ['_name' => 'my-route']]);
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/new-article',
'accept-charset' => $encoding,
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertHtml($expected, $result);
}
/**

0 comments on commit 30f9168

Please sign in to comment.
You can’t perform that action at this time.