Check out sfJqueryReloadedPlugin. It contains jQuery versions of the
classic Symfony JavaScript helpers. If some of the helpers that have
been removed in Symfony 1.3 are not reimplemented in
sfJqueryReloadedPlugin, feel free to copy or reimplement them there
(with a jq_ prefix) and/or bring it up with the devs (including me).

For compatibility reasons the jQuery versions of the helpers have a
jq_ prefix, so it's safe to reimplement things that also exist in the
core in 1.2, and change the other helpers to utilize those
reimplemented versions... but please code them correctly (:

Having said all that, I tend to agree that jQuery is so expressive and
concise that the helpers don't really add much elegance. I use the
helpers less and less myself.

Some cases are complex enough that I suppose helpers still make sense.
remote_form_tag looks something like this if you write it directly in
jQuery:

<script>
$('form').submit(function() {
  $.post(<?php echo json_encode(url_for('mymodule/myaction')) ?>,
    $(this).serialize(),
    function(data) {
      $('#mycontainer').html(data);
    }
  );
}
</script>

That's pretty darn elegant, but it's such a common pattern that the
helper is still worth it to save typing and avoid bugs.

The most important modern PHP feature for javascript interaction,
IMHO, is the json_encode method. People use it mostly for AJAX
responses but it is also fantastic for emitting a parameter to a
javascript function (string, number, array, hash, - json_encode will
escape it properly):

callAFunction(<?php echo json_encode($myvar) ?>);

Or setting variables:

var mydata = <?php json_encode($myBigComplexHashOfArraysNoProblem) ?>;

Others will tell you that your JavaScript should be entirely separate
in clean .js files that pick up on IDs and class names in the HTML and
do something brilliant with them - the progressive enhancement
philosophy. I think they are mostly right, but there IS a need
sometimes to kick some javascript data and maybe even code out there
on the fly in the context where you have the relevant variables at
hand, IMHO.

On Nov 24, 8:07 am, Gareth McCumskey <[email protected]> wrote:
> Its not -just- the fact that my Javascript skills aren't as good as my PHP,
> I -can- code Javascript, but I far prefer re-using dynamically generated
> Javascript, like through the sfProtoculous helpers, which will be by far
> more bug free than my potentially far more error-prone handcrafted
> Javascript.
>
> If I need to I can, its no biggie, but I'd rather not if I don't have to.
>
> On Tue, Nov 24, 2009 at 2:56 PM, Massimiliano Arione 
> <[email protected]>wrote:
>
>
>
>
>
> > On 24 Nov, 10:56, Gareth McCumskey <[email protected]> wrote:
> > > Thanks for the info guys and after going through the documentation on
> > what
> > > is going to be deprecated I had another question.
>
> > > I see that the ajax helpers (remote_function(), link_to_remote(), etc)
> > are
> > > deprecated in 1.3. My question is what is replacing this as we use those
> > > helpers quite extensively in our application (and for good reason :P). If
> > > its being removed surely there must be a replacement? One of the things I
> > > liked about symfony was that my Javascript knowledge is no where near as
> > > good as my PHP and being able to use PHP based function to implement some
> > > pretty impressive Javascript functionality was a real bonus.
>
> > Believe me: it's not.
> > Javascript should be always used with Javascript itself, just because
> > it needs to be separated from HTML context.
> > Try to learn some Javascript, it's not so hard and you don't need to
> > start from zero: you can use one of many frameworks (my advice is
> > jQuery).
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "symfony users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<symfony-users%2bunsubscr...@goog 
> > legroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/symfony-users?hl=en.
>
> --
> Gareth McCumskeyhttp://garethmccumskey.blogspot.com
> twitter: @garethmcc

--

You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en.


Reply via email to