Why does dojo work when using CDN but not when using $this->dojo->setLocalPath (using Zend Dojo)?

别说谁变了你拦得住时间么 提交于 2019-12-25 04:26:45

问题


I have been using Dojo hosted on Google's CDN. I just downloaded the development version so I can do some debugging. When using dojo stored locally, Firebug reports several syntax errors. They all look like this:

SyntaxError: syntax error
(no script)(""en-us"")bootstrap.js (line 601)
(no script)(""dojo.cldr"", ""number"")bootstrap.js (line 590)
(no script)(""dojo.cldr"", ""number"")loader.js (line 634)
(no script)(""./number.js"", ""dojo.number"")loader.js (line 76)
(no script)(""dojo.number"")loader.js (line 411)
(no script)(""./currency.js"", ""dojo.currency"")loader.js (line 76)
(no script)(""dojo.currency"")loader.js (line 411)
(no script)(""../dijit/form/CurrencyTextBox.js"", ""dijit.form.CurrencyTextBox"")loader.js (line 76)
(no script)(""dijit.form.CurrencyTextBox"")loader.js (line 411)
[Break on this error] (601 out of range 505)
bootstrap.js (line 601)

I know I have Dojo set up correctly throughout my layout, views, and controllers because dojo works fine if I use a CDN. I've also verified that the localpath resolves properly, which it does.

This is what the initialization looks like using CDN (this works correctly):

<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headScript();
if ($this->dojo()->isEnabled()) {
    $this->dojo()->setCdnVersion('1.5')
                 ->addStyleSheetModule('dijit.themes.claro');
    echo $this->dojo();
}
?>
</head>

And this is what it looks like using the local version:

<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headScript();
if ($this->dojo()->isEnabled()) {
    $this->dojo()->setLocalPath('/js/dojo/dojo.js')
                 ->addStyleSheetModule('dijit.themes.claro')
                 ->setDjConfigOption('parseOnLoad', true)
                 ->setDjConfigOption('isDebug', true);
    echo $this->dojo();
}
?>
</head>

What am I doing wrong with the localpath that is making these syntax errors occur?


回答1:


It appears that you have to "build" dojo when you download the source and want to run it locally. Somehow I missed this as a requirement of using a local path version of dojo. At any rate, I was finally able to get dojo to run correctly locally by doing a custom build. I found this dojo reference very helpful:

http://docs.dojocampus.org/quickstart/custom-builds

In the util/buildscripts folder in the dojo distribution, there are several predefined build profiles as well. I suspect that you could use one of these to build the whole dojo distribution, but I figured if I'm going to this much trouble, might as well get an optimized build out of it.

My build profile ended up looking like this:

dependencies ={

   layers:  [
       {
       name: "mydojo.js",
       dependencies: [
           "dojox.grid.DataGrid",
           "dojox.Data.QueryReadStore",
           "dijit.form.ComboBox",
           "dijit.form.ValidationTextBox",
           "dijit.form.CurrencyTextBox",
           "dijit.form.PasswordTextBox",
           "dijit.form.RadioButton",
           "dijit.form.Button",
           "dijit.form.CheckBox",
           "dijit.form.DateTextBox"
       ]
       }
   ],

   prefixes: [
       [ "dijit", "../dijit" ],
       [ "dojox", "../dojox" ]
   ]

 };

I placed this in the /util/buildscripts/profiles folder, named "myProfile.profile.js".

Then, I ran the build script from /util/buildscripts:

./build.sh profile=myProfile action=release optimize=shrinksafe.keepLines layerOptimize=shrinksafe.keepLines releaseName=myRelease localeList=en-us,es-es version=0.1.dev

Copy the resulting build from /release/myRelease to your website's javascript folder, i.e. /js/myRelease/.

The important commandline options are "profile" and "action", the others are optional. You can get a full description of what each commandline option means at the url I provided above. I customized these options to my particular needs--yours may be very different and I have provided them only as an example of what mine looked like in the end. If you are on windows, instead of "build.sh", use "build.bat".

Then, to set Zend to use this build, I did the following in my layout.phtml file:

if ($this->dojo()->isEnabled()) {
        $this->dojo()->setLocalPath($this->baseUrl() . '/js/myRelease/dojo/dojo.js')
             ->addStyleSheetModule('dijit.themes.claro')
             ->setDjConfigOption('isDebug', true)
             ->setDjConfigOption('debugAtAllCosts', true)
             ->addLayer($this->baseUrl() . '/js/myRelease/dojo/mydojo.js')                
             ;
}

Using "addLayer" for the custom build is what finally got this working for me. I hope this helps save someone else a little time!




回答2:


I have had the exact same problem. It seems to have something to do with localization but I cannot figure out the reason.

There is a work-around, though, which will do the job in some cases: In the dijit/nls directory, create en and en-us directories and copy into them the common.js and loader.js files.

You may have to do this for more than one dijit, depending on where the dijit looks for localization files.

If you come across a better solution, MikeH, please post it here. Earlier today I posted this problem to the dojo forum and will follow up by linking to this thread. Hopefully someone will have a non-stopgap fix.

ken



来源:https://stackoverflow.com/questions/3356442/why-does-dojo-work-when-using-cdn-but-not-when-using-this-dojo-setlocalpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!