Friday, October 30, 2009

Ajax in Symfony

Changing the Content Depends upon the User Selected Value in Select Box.
-----------------------------------------------------------------------------------------

Here The Functionality is We need to get the List of Documents depends upon the Category Choosen From the Selectbox.

//actions.class.php

public function executeOpen(){

$cat_criteria = new Criteria();
$categories = CategoriesPeer::doSelect($cat_criteria);

foreach($categories as $category) {
$options[$category->getId()] = $category->getName();
}

$this->categories = $options;


}

//openSuccess.php

select_tag("category", options_for_select($categories), array("onChange" => remote_function(array(
'update' => 'docs',
'url' => 'manuals/documents',
'with' => "'id=' + \$F('category')",
))
)); ?>

&lt div id="docs" &gt &lt /div &gt


//actions.class.php

public function executeDocuments() {
$cat_id = $this->getRequestParameter('id');
$c = new Criteria();
$c->add(DocumentsPeer::CATEGORY_ID,$cat_id);
$documents = DocumentsPeer::doSelect($c);
$result = "";
foreach($documents as $document) {
$result .= "&lta href='/orm/web/manuals/view/id/".$document->getId()."'>&gt".$document->getTitle()."<&lt/a>&gt<&lt>&gt";
";
//$result .= "";
}
echo $result;
return SfView::NONE;
}