Friday, October 27th, 2006

Projax: PHP Generators for Prototype and Script.aculo.us

Category: PHP, Prototype

<>p>Projax is a port of the Rails helpers that wrap the JavaScript required for Prototype and Script.aculo.us code from Ruby, to PHP classes.

Getting Started

  1. $projax = new Projax();
  2.  
  3. Please enter your year of birth :
  4. < ?=$projax->text_field_with_auto_complete('dob',null,array('url'=>'index.php?task=ajax'));?>
  5.  
  6. for($i=1900;$i&lt;2006;$i++)$ret_val.=(strstr($i,$_POST['dob']))?'<li>'.$i.'</li>':'';
  7. echo '<ul>'.$ret_val.'</ul>';

The User Guide details the available functions:

JavaScript Helpers

  • button_to_function($name,$function=null)
  • link_to_function($name,$function,$html_options=null)
  • tag($content)
  • escape($javascript)

Prototype Helpers

  • evaluate_remote_response()
  • form_remote_tag($options)
  • link_to_remote($name,$function,$html_options=null)
  • observe_field($field_id,$options =null)
  • observe_form($form,$options=null)
  • periodically_call_remote($options=null)
  • remote_function($options)
  • submit_to_remote($name,$value,$options=null)
  • dump($javascript)
  • ID($id,$extend=null)
  • alert($message)
  • assign($variable,$value)

Script.aculo.us Helpers

  • dragable_element($element_id,$options=null)
  • drop_receiving_element($element_id,$options=null)
  • sortable_element($element_id,$options=null)
  • visual_effect($name,$element_id=false,$js_options=null)
  • auto_complete_field($field_id,$options=null)
  • in_place_editor($field_id,$options=null)

Some of these look a tad overkill? :)

Related Content:

  • Ajax everywhere: Which framework to choose?
    Writing and debugging Ajax, a JavaScript- and XML-driven development technique, can be difficult. In this tip, an expert introduces several frameworks...
  • Ajax everywhere: Which framework to choose?
    Writing and debugging Ajax, a JavaScript- and XML-driven development technique, can be difficult. In this tip, an expert introduces several frameworks...
  • Choosing an Ajax framework
    Your customers won't have to fear Ajax if they have the right tools to work with. Help them determine which Ajax-specific framework, library or...

Posted by Dion Almaer at 9:15 am
9 Comments

+++--
3.6 rating from 66 votes

9 Comments »

Comments feed TrackBack URI

The in-place editor has a problem. If you delete the contents and save, then try to edit that field again to enter some data its gone.

Comment by Mark Haliday — October 27, 2006

Its not a bug , you can spcify extra options to take care of this , for options please check out
http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor

Comment by Vikas — October 27, 2006

Hi Vikas,

Great work! anyway.. was the demo build together with codeigniter framework? i’ve noticed because the getting started guide is similar to codeigniter…

cheers c”,)

Comment by r00t — October 29, 2006

We’ve been working hard enough to keep the MVC structure clear so that they are easily maintain. Javascript is for the client side, and php is for the server side. Mixing those two into one is just not a good idea to me. one of reason I never got too excited about the Ruby’s prototype support is because of the nasty mixture of two different codes. It makes it harder to maintain and debug. I can’t believe now is the PHP’s turn.

Comment by Simon Jia — October 29, 2006

@ r00t – Projax intial release was for CI , so the manual looks like CI’s.
@ Simon Jia – Yep u are right , for CodeIgniter ( a MVC framework ) I did generate the JS in the controller which was passed to the view for display, but doin so meant passing a lot of extra variables, So i found it best to include it in the view ( since it generates JS anyhow ).

Comment by Vikas — October 29, 2006

[...] Projax: PHP Generators for Prototype and Script.aculo.us Explication et exemple de Projax sur le site Ajaxian (tags: ajax billet php web2.0 programming tips javascript generator) [...]

Pingback by links for 2006-10-30 « Mogore, une femme en or — October 30, 2006

November 7 Linkdump

Royale Noir is the best-looking Windows XP theme I’ve seen. If you know enough about Windows to install it, you…

Trackback by Joe Grossberg — November 7, 2006

[...] Ajaxian » Projax: PHP Generators for Prototype and Script.aculo.us Для любителей сделать что-то на AJAX – генераторы для Prototype и Script.aculo.us на PHP (tags: php prototype scriptaculous ajax javascript вебдев программирование) [...]

Pingback by Binary Look » links for 2006-11-08 — November 8, 2006

$projax->sortabe_element does not call the url for updating… bug?

Comment by dave — August 28, 2007

Leave a comment

You must be logged in to post a comment.