From 39847952057a446f752e8f7094c09b9fe54f650a Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 18 Jan 2006 04:38:21 +0000 Subject: [PATCH] Merging fixes to trunk Revision: [1829] Fixing AjaxHelper::form() Revision: [1828] Added check to return false is passing an empty string to requestAction(), method would seg fault if param was empty. Fixing another problem found when passing fields to the model methods. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1830 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/libs/model/datasources/dbo_source.php | 1 + cake/libs/object.php | 21 ++++++---- cake/libs/view/helpers/ajax.php | 47 ++++++++++++++++++---- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index f9f50a242..b188ee609 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.6.1827 RC 1 \ No newline at end of file +0.10.6.1830 RC 2 \ No newline at end of file diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index da40bf5cc..5dd17132f 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -366,6 +366,7 @@ class DboSource extends DataSource $null = null; $array = array(); $linkedModels = array(); + $this->__bypass = false; if(!empty($queryData['fields'])) { diff --git a/cake/libs/object.php b/cake/libs/object.php index 70d2c5d46..c5aedaa85 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -96,21 +96,28 @@ class Object */ function requestAction ($url, $extra = array()) { - $dispatcher =& new Dispatcher(); - if(in_array('return', $extra)) + if(!empty($url)) { - $extra['return'] = 0; - $extra['bare'] = 1; + $dispatcher =& new Dispatcher(); + if(in_array('return', $extra)) + { + $extra['return'] = 0; + $extra['bare'] = 1; ob_start(); $out = $dispatcher->dispatch($url, $extra); $out = ob_get_clean(); return $out; + } + else + { + $extra['return'] = 1; + $extra['bare'] = 1; + return $dispatcher->dispatch($url, $extra); + } } else { - $extra['return'] = 1; - $extra['bare'] = 1; - return $dispatcher->dispatch($url, $extra); + return false; } } diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index 283213d37..c4ad39692 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -257,17 +257,50 @@ class AjaxHelper extends Helper * will work just like a regular submission as viewed by the receiving side (all elements available in params). * The options for specifying the target with :url and defining callbacks is the same as link_to_remote. * - * @param string $id Form id - * @param array $html_options HTML tag options - * @param array $options Callback options - * @return string JavaScript code + * @param array $params Form id + * @param array $type How form data is posted: 'get' or 'post' + * @param array $options Callback/HTML options + * @return string JavaScript/HTML code */ - function form($id, $options = array()) + function form($params = null, $type = 'post', $options = array()) { + if (is_array($params)) + { + extract($params, EXTR_OVERWRITE); + if (!isset($action)) + { + $action = null; + } + if (!isset($type)) + { + $type = 'post'; + } + if (!isset($options)) + { + $options = array(); + } + } + else + { + $action = $params; + } + $htmlOptions = $this->__getHtmlOptions($options); - $htmlOptions['id'] = $id; + $htmlOptions['action'] = $action; + + if(!isset($htmlOptions['id'])) + { + $htmlOptions['id'] = 'form'.intval(rand()); + } $htmlOptions['onsubmit'] = "return false;"; - return $this->Html->formTag(null, "post", $htmlOptions) . $this->Javascript->event("$('$id')", "submit", "function(){" . $this->remoteFunction($options) . ";}"); + + if(!isset($options['with'])) + { + $options['with'] = 'Form.serialize(this)'; + } + $options['url'] = $action; + + return $this->Html->formTag($htmlOptions['action'], $type, $htmlOptions) . $this->Javascript->event("$('".$htmlOptions['id']."')", "submit", "function(){" . $this->remoteFunction($options) . ";}"); } /**