定制 radnan/rdn-require-js 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

radnan/rdn-require-js

Composer 安装命令:

composer require radnan/rdn-require-js

包简介

Zend Framework 2 RequireJS module

README 文档

README

The RdnRequireJS ZF2 module integrates the RequireJS library into your project.

How to install

  1. Use composer to require the radnan/rdn-require-js package:

    $ composer require radnan/rdn-require-js:1.*
  2. Activate the module by including it in your application.config.php file:

    <?php
    
    return array(
        'modules' => array(
            'RdnRequireJS',
            // ...
        ),
    );

How to use

Create your RequireJS modules in your project's public/ directory:

// public/Bar.js

define(['./Foo'], function(Foo)
{
	Foo.log('Hello World!');
});

Then, in your view templates, call the requireJS($name) view helper with the module name as the argument:

/** @var Zend\View\Renderer\PhpRenderer $this */

<?php $this->requireJS('Bar') ?>

The view helper will include the RequireJS library along with the requested modules as inline scripts.

Multiple dependencies

You can call the view helper multiple times and it will keep appending the module dependencies. You can also provide an array to include multiple deps at a time:

/** @var Zend\View\Renderer\PhpRenderer $this */

<?php $this->requireJS(['Bar', 'Baz']) ?>

Code completion

If you'd like to have code completion for this helper, include the following in your PhpRenderer class:

namespace App\View\Renderer;

use Zend\View\Renderer\PhpRenderer as ZendPhpRenderer;

/**
 * @method requireJS(\string $dependencies = array())
 */
class PhpRenderer extends ZendPhpRenderer
{
}

Then, simply type hint the $this variable to this class in your view templates.

Library

The RequireJS library is, by default, included from cdnjs. You can configure this using the rdn_require_js.library option:

<?php

return array(
	'rdn_require_js' => array(
		'library' => '/path/to/local/require.js',
	),
);

This path should be relative to your project's base path. The view helper will use the basePath() view helper to resolve the full path.

Configuration

You can manage the default requireJS configuration using the rdn_require_js.config option:

<?php

return array(
	'rdn_require_js' => array(
		'config' => array(
			'baseUrl' => '/modules',

			'paths' => array(
				'App' => 'app/js',
			),

			'packages' => array(
				'App',
			),
		),
	),
);

RequireJS config documentation

统计信息

  • 总下载量: 10.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固