Zend_Dojo_Form not rendering in layout

2019-08-20 17:37发布

问题:

I have a quick question about adding Zend_Dojo_Form into Zend_layouts.

I have a Zend_Dojo_Form that I want to display in the layout that is used for a particular controller. I can add the form to the layout without any issue however the dojo elements fail to render, as they would do if I added the form to a standard view.

Is there any reason why this would be the case? Do I need to do something to the layout so that it will enable the components for this embedded form in the layout. Any other dojo enabled forms that are added in the view using this layout work fine.

My form is created in the usual way:

class QuickAddJobForm extends Zend_Dojo_Form{


public function init(){

    $this->setName('quickaddjobfrm')
        ->setMethod('post')
        ->setAction('/addjob/start/);


    /*We now create the elements*/
    $jobTitle = new Zend_Dojo_Form_Element_TextBox('jobtitle',
        array(
            'trim' => true              
        )
    );
    $jobTitle->setAttrib('style', 'width:200px;')
        ->addFilter('StripTags')
        ->removeDecorator('DtDdWrapper')
        ->removeDecorator('HtmlTag')
        ->removeDecorator('Label');

      ....
  $this->addElements(array($jobTitle, ....));

In the controller I declare the layout and the form in the init function:

 public function init(){
   $this->_helper->layout->setLayout('add-layout');
   $form = new QuickAddJobForm();
   $form->setDecorators(array(array('ViewScript', array('viewScript' => 'quickAddJobFormDecorator.phtml'))));

 $this->_helper->layout()->quickaddjob = $form;

In my layout Where I want the form I have:

  echo $this->layout()->quickaddjob;

Why would adding this form in the layout fail to render/add the Dojo elements? All that is currently being displayed are text boxes, rather than some of the other components such as ComboBoxes/FilteringSelects etc...

Thanks in advance.

回答1:

This is what I have in my layout.phtml

<head>

    <style type="text/css" media="screen">
        @import url("<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/includes/js/dojo/dijit/themes/tundra/tundra.css");

<?php
$this->dojo()->enable();
    if ($this->dojo()->isEnabled()) {
        $this->dojo()->setLocalPath($this->baseUrl() .  '/includes/js/dojo/dojo/dojo.js');
        echo $this->dojo();
    }
?>
</head>
<body class="tundra">

In my bootstrap I use

    protected function _initDojo()
{
    $this->bootstrap('frontController');
    $this->bootstrap('view');
    $view = $this->getResource('view');

    $appConfig = Zend_Controller_Front::getInstance()->getParam('appconfig');
    Zend_Dojo::enableView($view);
    Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
    $view->dojo()->setLocalPath(Zend_Controller_Front::getInstance()->getBaseUrl() . '/includes/js/dojo/dojo/dojo.js')
    ->addLayer(Zend_Controller_Front::getInstance()->getBaseUrl() . '/includes/js/dojo/dojo/nirvanaDojo.js')
    ->requireModule('dijit.TitlePane')
    ->requireModule('dijit.InlineEditBox')
    ->requireModule('dijit.ProgressBar')
    ->requireModule('dijit.form.DateTextBox')
    ->addStyleSheetModule('dijit.themes.tundra');
}

Now I can call $this->form anytime in my view scripts, and the Dojo renders properly

The problem I have is I can't cant Dojo to render a form in Modal window



回答2:

Iam not 100% Sure, but i think you must add Dojo to your Application. Try

 $this->dojo()->enable(); 
 echo $this->dojo(); 

in your Layout.phtml



回答3:

If you use Zend_Dojo_Forms in your layout be sure to render them before calling

echo $this->dojo();

You can do that with something like that:

//in HTML-Head:
$content = $form->render();
echo $this->dojo();

//later...
echo $content;