Zend framework with dojo


Zend framework with dojo

我正在开发一个应用程序与zend框架,我想添加dojo框架。我做了以下几点:boot .php:

public function _initViewHelpers()  
{  
    $this->bootstrap('layout');  
    $layout = $this->getResource('layout');  
    $view = $layout->getView();
    $view->addHelperPath('Zend/Dojo/View/Helper',
                                    'Zend_Dojo_View_Helper');
    $view->dojo()->enable();  
}  
我layout.phtml

<?php echo $this->doctype() ?>
<html>
    <head>
    <?php echo $this->headTitle() ?>
    <?php echo $this->headMeta() ?>
    <?php echo $this->headLink() ?>
    <?php echo $this->headStyle() ?>
    <?php if ($this->dojo()->isEnabled()){
        $this->dojo()->setLocalPath('/js/dojo/dojo.js')
                     ->addStyleSheetModule('dijit.themes.claro');
        echo $this->dojo();
       }
    ?>
    <?php echo $this->headScript() ?>
</head>
<body class="claro">
    <?php echo $this->layout()->content ?>
    <?php echo $this->inlineScript() ?>
</body>

最后我的索引。php:

<script type="text/javascript">
dojo.addOnLoad(function() {
    // our test data store for this example:
    var store4 = new dojo.store.JsonRest({
        target: '/guestbook/test'
    });
    storeData =  new dojo.data.ItemFileReadStore( 
            { data:store4 }
        ); 
    // set the layout structure:
    var layout4 = [{
        field: 'Title',
        name: 'Title of Movie',
        width: '200px'
    },
    {
        field: 'Year',
        name: 'Year',
        width: '50px'
    },
    {
        field: 'Producer',
        name: 'Producer',
        width: 'auto'
    }];
    // create a new grid:
    var grid4 = new dojox.grid.DataGrid({
        query: {
            Title: '*'
        },
        store: storeData,
        clientSort: true,
        rowSelector: '20px',
        structure: layout4
    },
    document.createElement('div'));
    // append the new grid to the div "gridContainer4":
    dojo.byId("gridContainer4").appendChild(grid4.domNode);
    // Call startup, in order to render the grid:
    grid4.startup();
});

<div id="gridContainer4" style="width: 100%; height: 100%;">
</div>
<?php // setup required dojo elements:
$this->dojo()->enable()
             ->setDjConfigOption('parseOnLoad', true)
             ->requireModule('dojo.store.JsonRest')
             ->requireModule('dojo.data.ObjectStore')
             ->requireModule('dojo.data.ItemFileReadStore')
             ->requireModule('dojox.data.QueryReadStore')
             ->requireModule('dojox.grid.DataGrid')
             ->addStyleSheet('/js/dojox/grid/resources/claroGrid.css')
             ->addStyleSheet('/js/dojox/grid/resources/Grid.css'); ?>

当我试图访问页面localhost/留言簿,页面呈现,但没有数据网格,这就像javascript没有启用…url/guestbook/test返回一个json对象。在firebug中,没有javascript错误,dojo.js被加载,dojo模块和css也被加载。我不明白发生了什么!谢谢:)

您正在创建网格并将其放在未附加的div中。相反,附加网格gridContainer4

// create a new grid:
var grid4 = new dojox.grid.DataGrid({
    query: {
        Title: '*'
    },
    store: storeData,
    clientSort: true,
    rowSelector: '20px',
    structure: layout4
}, 
dojo.byId("gridContainer4"));