Do an ZendX autocomplete in a layout
I would like to use ZendX_Jquery autocomplete in a partial, which is in my layout. How can I do that : My layout :
<div class="prefix_11 grid_5" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml"); ?>
</div>
An action :
public function autocompleteAction($search='') {
$this->view->autocompleteElement = new ZendX_J开发者_C百科Query_Form_Element_AutoComplete('ac');
$this->view->autocompleteElement->setJQueryParam('source', '/searchengine/getsearch');
$this->view->autocompleteElement->setJQueryParam('minLength',
$this->configApplication->autocomplete->max_cars);
}
How can I use it in the partial, in the layout ?
How can i send the autocompleteElement in the partial view ?,
Thanks to help.
Fabrice
@fabrice
I had the same problem using autocomplete with my layout and I have solved it with the following:
- Use placeholder for my searchBox
- Create a Zend_Controller_Plugin that extends Zend_Controller_Plugin_Abstract
- in predispatch execute method renderUiWidgetElement of autocomplete element.
- set the placeholder with the form
Example:
class myLibrary_Controller_Plugin_SearchBox extends Zend_Controller_Plugin_Abstract
{
public function preDispatch()
{
$this->searchBox();
}
public function searchBox()
{
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->initView();
$view = $viewRenderer->view;
$searchForm = new Application_Form_JQueryForm();
$searchForm->acProduct->renderUiWidgetElement();
$view->placeholder('searchBox')->set($searchForm);
}
}
The key is to launch method renderUiWidgetElement();
. Without it, the layout will not add the neccesary javascript to the autocomplete element. I got this information from here: http://cientouno.be/blog/categorie/zend-framework
Thanks a lot to cientouno!
Thank you, but, I used the ActionStack for display on every page. And do, I use a form.
public function autocompleteAction() {
$formAutoComplete = new Frontoffice_Form_Autocomplete();
$this->view->autocompleteElement = $formAutoComplete;
$this->_helper->viewRenderer->setResponseSegment('autocomplete');
}
and, in the layout :
<div class="prefix_10 grid_6" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml");
echo $this->layout()->autocomplete;
?>
</div>
You can send the autocompleteElement in the partial view with this code.
<div class="prefix_11 grid_5" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml", array('autocompleteElement ' => $this->autocompleteElement); ?>
</div>
精彩评论