在Zend Framework中包括Require.js的最佳方法是什么?我当前在zend框架中调用js文件的方式如下:
<?php echo $this->jQuery()->setLocalPath($this->path('js/jquery/jquery-1.7.1.min.js'))
->enable()
->setUiLocalPath($this->path('js/jquery/jquery-ui-1.8.16.custom.min.js'))
->uiEnable()
->addStylesheet($this->path('css/jquery/jquery-ui-1.8.16.custom.css'));
echo $this->headScript()->appendFile($this->path('js/jquery.tipTip.js'))
->appendFile($this->path('js/customScripts/facebook.js'))
->appendFile($this->path('js/facebook/jquery.facebook.multifriend.select.js'))
->appendFile($this->path('js/customScripts/logindialog.js'))
->appendFile($this->path('js/customScripts/globalFunctions.js'))
->appendFile($this->path('js/kendo.web.min.js'))
->appendFile($this->path('js/customScripts/fancyAlert.js'))
->appendFile($this->path('js/inc/jquery.mousewheel.min.js'))
->appendFile($this->path('js/pagination-jq.js'))
->appendFile($this->path('js/jquery.tools.min.js'))
->appendFile($this->path('js/fancybox/jquery.fancybox-1.3.4.pack.js'))
->appendFile($this->path('js/jq-history/scripts/jquery.history.min.js'));
?>
参考方案
使用require.js,您只需要将一个脚本文件添加到头部(或在关闭</body>
之前)。
然后,在require.js配置文件和模块中,您将实际定义每个模块的依赖性。
就您而言,我将手动添加脚本文件:
<script src="require.js" data-main="path/to/mainScriptFile"></script>
否则,可以在Zend中这样做:
$this->headScript()
->setAllowArbitraryAttributes(true)
->appendFile($this->path('js/require.js'), "text/javascript", array('data-main' => 'path/to/mainScriptFile');
但是在这一点上,只需手动输入脚本标签,就可以减少开销。
希望对您有所帮助!
PHP:对数组排序 - php请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…
PHP PDO组按列名称查询结果 - php以下PDO查询返回以下结果:$db = new PDO('....'); $sth = $db->prepare('SELECT ...'); 结果如下: name curso ABC stack CDE stack FGH stack IJK stack LMN overflow OPQ overflow RS…
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
PHP Array重复数据计数 - php我在PHP Array中有标题和语言数据。我需要显示重复的标题计数。请检查以下数组格式。Array ( [0] => Array ( [title] => My_title1 [language] => English ) [1] => Array ( [title] => My_title1 [language] => …
PHP-全局变量的性能和内存问题 - php假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…