为什么dojo在使用CDN时工作,但是在使用$ this-> dojo-> setLocalPath(使用Zend Dojo)时不工作? [英] Why does dojo work when using CDN but not when using $this->dojo->setLocalPath (using Zend Dojo)?

查看:156
本文介绍了为什么dojo在使用CDN时工作,但是在使用$ this-> dojo-> setLocalPath(使用Zend Dojo)时不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Dojo托管在Google的CDN上。我刚刚下载开发版本,所以我可以做一些调试。当使用本地存储的dojo时,Firebug会报告几个语法错误。他们都是这样的:

  SyntaxError:syntax error 
(no script)(en-us )bootstrap.js(第601行)
(无脚本)(dojo.cldr,number)bootstrap.js(第590行)
(无脚本)(dojo .cldr,number)loader.js(第634行)
(无脚本)(./ number.js,dojo.number)loader.js 76)
(无脚本)(dojo.number)loader.js(第411行)
(无脚本)(./ currency.js,dojo.currency )loader.js(第76行)
(无脚本)(dojo.currency)loader.js(第411行)
(无脚本)(../ dijit / form / CurrencyTextBox.js,dijit.form.CurrencyTextBox)loader.js(第76行)
(无脚本)(dijit.form.CurrencyTextBox)loader.js(第411行)
[打破此错误](超出范围505的601)
bootstrap.js(第601行)

我知道我的Dojo在我的布局,视图和控制器中正确设置,因为如果我使用CDN,dojo可以正常工作。我也验证了本地路径正确解析,它是做什么的。



这是初始化看起来像使用CDN(这可以正常工作):

 < 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>

这就是使用本地版本的样子:

 < 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>

发生这些语法错误的本地路径出现什么问题?

解决方案

看来,当您下载源代码并希望在本地运行时,您必须构建dojo。不知怎的,我错过了这个使用本地路径版本的dojo的要求。无论如何,我终于可以通过自定义构建在本地运行dojo。我发现这个dojo参考非常有用:



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



在dojo发行版的util / buildscripts文件夹中,有几个预定义的构建配置文件也。我怀疑你可以使用其中的一个构建整个dojo分发,但是我想如果我要这么麻烦,也可以从中优化构建。



我的构建个人资料最终如下所示:

  dependencies = {

layers:[
{
name:mydojo.js,
依赖关系:[
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
]
}
],

前缀:[
[dijit,../dijit],
[dojox,../dojox]
]

};

我把它放在/ util / buildscripts / profiles文件夹中,命名为myProfile.profile.js



然后,我从/ 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 

将生成的版本从/ release / myRelease复制到您网站的javascript文件夹,即/ js / myRelease /.



重要的命令行选项是配置文件和操作,其他选项是可选的。您可以在上面提供的url中获取每个命令行选项的含义。我根据自己的特殊需求定制了这些选项 - 你们可能会有很大的不同,我已经提供了这些选项,作为我最终看到的一个例子。如果你在Windows上,而不是build.sh,请使用build.bat。



然后,要设置Zend以使用此构建,我做了以下在我的layout.phtml文件中:

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

为自定义构建使用addLayer是最终为我工作的。我希望这有助于拯救别人一点点!


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?

解决方案

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!

这篇关于为什么dojo在使用CDN时工作,但是在使用$ this-&gt; dojo-&gt; setLocalPath(使用Zend Dojo)时不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆