On Tue, Feb 15, 2011 at 5:31 PM, netusco <[email protected]> wrote:
> in the book I had found the function set() from JsHelper but there's no
> examle there...
>
> googleing I found an example that doesn't work for me... it's like this:
>
> after loading Js Helper on the controller...
>
> $this->Js->set('someTest', 'amazing discovery');
>
> alert('Set in the CakePHP view using JsHelper: ' +
> window.your_project_name.someTest);
I don't use JsHelper at all, perhaps there's something built-in. But
consider that all that PHP is doing is outputting a bunch of strings
that are then interpreted as HTML & JS by the browser. Here's an
element for adding sorting capabilities. I pass two vars to the
element, $route and $selector. From $route, I get another var, $url.
These are then added to the JS routine so they're read on the
clientside.
$this->Html->script('lib/jquery-ui-1.8.5.sortable.min', array('inline'
=> false));
$url = Router::url($route);
$script =<<<EOT
$(function()
{
var \$list = $('${selector}');
\$list.sortable({
handle : '.Handle',
axis: 'y',
containment: 'parent',
helper: 'clone',
opacity: 0.6,
scroll: true,
tolerance: 'intersect',
update : function(event, ui)
{
$.loading.align = 'left';
$.loading.css.marginTop = '20px';
$.loading.css.marginLeft = '-60px';
ui.item.loading();
$.ajax({
url: '${url}',
data: \$list.sortable('serialize'),
cache: false,
dataType: 'html',
success: function(data, textStatus,
XMLHttpRequest)
{
ui.item.loading(false);
}
});
}
});
});
EOT;
$this->Html->scriptBlock($script, array('inline' => false));
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php