Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: Zend_Controller
-
Labels:None
Description
if you have data from a DB table groepen
groepen [id,name]
name is what you want to show the user, id is what you need
I have a table offices
offices [id, name, groepen_id]
groepen_id is a FK tot groepen
with my function you can place a filterselect for offices that shows all the groepen by name.
when I save to the offices table I just use the id instead of the group name.
<select dojoType="dijit.form.FilteringSelect"
name="state3"
autocomplete="false"
value="CA">
<option value="1" selected="selected">California</option>
<option value="2" >Illinois</option>
<option value="3" >New York</option>
<option value="4" >Texas</option>
</select>
id is the value in this case, name is the text the user sees.
When the user clicks submit we can get the value (id) of the record the user selected.
solutions:
Groepen is a Zend_Db_Table and has id and name column
$groepen = new Groepen();
$this->_helper->autoCompleteDojoExt($groepen->fetchAll()->toArray());
<?php
/**
- Zend Framework
* - LICENSE
* - This source file is subject to the new BSD license that is bundled
- with this package in the file LICENSE.txt.
- It is also available through the world-wide-web at this URL:
- http://framework.zend.com/license/new-bsd
- If you did not receive a copy of the license and are unable to
- obtain it through the world-wide-web, please send an email
- to license@zend.com so we can send you a copy immediately.
* - @category Zend
- @package Zend_Controller
- @subpackage Zend_Controller_Action_Helper
- @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
- @license http://framework.zend.com/license/new-bsd New BSD License
- @version $Id: AutoCompleteDojo.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
- @see Zend_Controller_Action_Helper_AutoComplete_Abstract
*/
require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
/**
- Create and send Dojo-compatible autocompletion lists
* - @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
- @category Zend
- @package Zend_Controller
- @subpackage Zend_Controller_Action_Helper
- @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
- @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_AutoCompleteDojoExt extends Zend_Controller_Action_Helper_AutoComplete_Abstract
{
/** - Validate data for autocompletion
- @param mixed $data
- @return boolean
*/
public function validateData($data)
{
if (is_array($data) && isset($data['items']) && is_array($data['items'])) { return true; }
return false;
}
/**
- Prepare data for autocompletion
- @param mixed $data
- @param boolean $keepLayouts
- @return string
*/
public function prepareAutoCompletion($data, $keepLayouts = false)Unknown macro: { $items = array(); foreach ($data as $value) { $items[] = array('label' => array_pop($value), 'name' => array_pop($value)); } $final = array( 'identifier' => 'name', 'items' => $items, ); return $this->encodeJson($final, $keepLayouts); }}
How is this different than the current Dojo AutoComplete action helper? Can you summarize? I'd rather modify that to be more general than to add additional helpers that muddy the waters with more variants.
For the record, we plan to update the Dojo autocomplete action helper to utilize Zend_Dojo_Data, which will also give more flexibility. I'm also thinking that a flag and/or setters for specifying either FilteringSelect or ComboBox would help make it more useful.