2008年12月9日星期二

Re: [fw-mvc] Zend dojo.data usage, i dont understand

-- vladimirn <nezaboravi@gmail.com> wrote
(on Tuesday, 09 December 2008, 05:38 AM -0800):
> Matt, thank you for the efforts you make to help me undesrtand this.
> I did as you told me, and i am not getting any results beside the form. Form
> is not dojo enabled, looks like ordinary input field

Two things.

First, did you use Zend_Dojo_Form or extend Zend_Dojo_Form? I'm
assuming, based on the fact that you got an input, that you did.

Second, did you specify a dijit theme at any point? If not, you need to
do two things:

* In your view script or your action, set the dijit them.

// from a view script:
$this->dojo()->addStylesheetModule('dijit.themes.tundra');

// from your action controller:
$this->view->dojo()->addStylesheetModule('dijit.themes.tundra');

* Set the "tundra" class on either the <body> element, or a div
surrounding the form. Let's try the latter:

<?
$this->dojo()->requireModule('dojox.data.QueryReadStore')
->addStylesheetModule('dijit.themes.tundra');
?>
<div class="tundra">
<?= $this->form ?>
</div>

That last example should have everything you need for the view script.

> Also i traped this error in firebug:
> Could not load 'dojo.data.QueryReadStore'; last tried
> './data/QueryReadStore.js'
> I have tried to
> ->requireModule('dojo.data.QueryReadStore')
> both in view script and in my bootstrap, but this error still persist.
>
> Another question is - is it important whats the name of autocompletAction
> from your example?
> If i want to pull data when click on link show All Members, does action
> inside your autocompleteAction() should go in eg. viewAction() and then in
> 'storeParams' i put storeParams=array('url'='members/view')?

All that's important is that the URL specified to the storeParams "url"
member resolves to something that can provide a dojo.data payload. I
used "autocompleteAction" simply as an example -- but if you have a
MembersController::viewAction() method you want to use as a handler,
specify '/members/view' for the url.


> Matthew Weier O'Phinney-3 wrote:
> >
> > -- vladimirn <nezaboravi@gmail.com> wrote
> > (on Tuesday, 09 December 2008, 02:43 AM -0800):
> >> I am stucked , cause i want to use zend dojo.data, but after many many
> >> hours
> >> reading zend documentation at
> >> http://framework.zend.com/manual/en/zend.dojo.data.html i am not able to
> >> make anything working.
> >> What i wish to do is the follow.
> >> When visitor click on link, i want to display text filed. Visitor start
> >> to
> >> type a name of member in that field, and typed name should be
> >> autocompleted,
> >> and all data of that member shows bellow.
> >> I saw this many time on various web sites, but i cant make this myself.
> >
> > It takes several steps.
> >
> > First, you need the appropriate form element. Both ComboBox and
> > FilteringSelect work for this, but have different capabilities:
> >
> > * ComboBox allows you to enter arbitrary text; if it doesn't match the
> > associated list, it is still considered valid. The text entered is
> > submitted -- *NOT* the option value. (This differs from normal
> > dropdown selects.)
> >
> > * FilteringSelect also allows you to enter arbitrary text, but it will
> > only be considered valid if it matches an option provided to it. The
> > option value is submitted, just like a normal dropdown select.
> >
> > Once you've chose the appropriate form element type, you then need to
> > specify a dojo.data store. If using Zend_Dojo_Form to build the element,
> > this is relatively painless:
> >
> > $form->addElement('ComboBox', 'myAutoCompleteField', array(
> > 'label' => 'My autocomplete field:',
> > 'storeId' => 'autocompleter', // used as a JS
> > variable name by dojo
> > 'storeType' => 'dojo.data.QueryReadStore', // type of dojo.data
> > store; this is a
> > // sane default
> > 'storeParams' => array(
> > 'url' => '/controller/action', // specify the
> > appropriate URL for
> > // data store handler
> > ),
> > ));
> >
> > You'll also need to ensure that the appropriate dojo.data store is
> > loaded in the request, so add the following in your view script when you
> > render the form:
> >
> > $this->dojo()->requireModule('dojo.data.QueryReadStore');
> >
> > Now that your form is setup, let's create an action that will feed the
> > dojo.data store. It might look like this:
> >
> > public function autocompleteAction()
> > {
> > // First, get the model somehow
> > $model = $this->getModel();
> >
> > // Then get some request parameters; here we use the GET params
> > $params = $this->getRequest()->getQuery();
> >
> > // Fetch results from the model; again, merely illustrative
> > $results = $model->query($params);
> >
> > // Now, create a Zend_Dojo_Data object.
> > // The first parameter is the name of the field that has a
> > // unique identifier. The second is the dataset. The third
> > // should be specified for autocompletion, and should be the
> > // name of the field representing the data to display in the
> > // dropdown.
> > // Assign this to the view
> > $this->view->data = new Zend_Dojo_Data('id', $results, 'name');
> > }
> >
> > Now, create a view script for the action, with the following contents:
> >
> > <?= $this->data ?>
> >
> > And now you should be good to go.
> >
> >> I read about dojo autocomplete helper, and i'v tried all examples from
> >> zend
> >> documentation, but no success.
> >> Can someone explain me what i should do, and how to make this? My idea is
> >> to
> >> have model members.php, controller MembersController.php (action
> >> indexAction and viewAction) and viewscript.
> >> Also, is it possible that once i i finish this (with a help of you, my
> >> zend
> >> friends) data displayed are actually displayed within zend dojo form,
> >> ready
> >> for editing?
> >> Any example would be appreciated.
> >> Even attending Matt's webinar about zend dojo wasnt help me lol
> >> In documentation there are some examples, which i copy pasted, but wont
> >> work
> >> for me :/
> >> Thanks,
> >> V
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Zend-dojo.data-usage%2C-i-dont-understand-tp20912322p20912322.html
> >> Sent from the Zend MVC mailing list archive at Nabble.com.
> >>
> >
> > --
> > Matthew Weier O'Phinney
> > Software Architect | matthew@zend.com
> > Zend Framework | http://framework.zend.com/
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Zend-dojo.data-usage%2C-i-dont-understand-tp20912322p20914843.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: