attach() public static method

Example: Media::attach('app', array( 'path' => '/var/www/website/app/webroot/extradir', 'prefix' => 'extradir' )); Media::attach('cdn', array( 'absolute' => true, 'path' => null, 'host' => 'http://my.cdn.com', 'prefix' => 'project1/assets' )); Media::attach('cdn', array( 'absolute' => true, 'path' => null, 'host' => array('my.cdn.com', 'secure.cdn.com'), 'scheme' => array('http://', 'https://'), 'prefix' => 'project1/assets', )); Media::attach('cdn', array( 'absolute' => true, 'path' => null, 'host' => array('my1.cdn.com', 'my2.cdn.com'), 'scheme' => 'http://', 'prefix' => 'project1/assets', ));
public static attach ( string $name, array $config = null ) : void
$name string The name of the media you wish to attach.
$config array Asset configuration options for the given scope. - `'path'` _string_: Path of the media. - `'prefix'` _string_: Contains the uri prefix. Such as `css`. - `'absolute'` _boolean_: Defaults to `false`. If you want to generate absolute URL's. - `'host'` _mixed_: String host, or array of hosts, of the media, if absolute is `true`. - `'scheme'` _mixed_: String scheme, or array of sc, of the media, if absolute is `true`.
return void
Beispiel #1
0
 public function testScopeBase()
 {
     $result = Media::asset('style.css', 'css');
     $this->assertEqual('/css/style.css', $result);
     Media::attach(false, array('base' => 'lithium/app/webroot'));
     $result = Media::asset('style.css', 'css');
     $this->assertEqual('/lithium/app/webroot/css/style.css', $result);
 }
Beispiel #2
0
 * other classes to be connected as handlers to convert `Collection` objects to other formats.
 *
 * The following connects the `Media` class as a format handler, which allows `Collection`s to be
 * exported to any format with a handler provided by `Media`, i.e. JSON. This enables things like
 * the following:
 * {{{
 * $posts = Post::find('all');
 * return $posts->to('json');
 * }}}
 */
use lithium\util\Collection;
Collection::formats('lithium\\net\\http\\Media');
// Mount assets directory as DOMAIN/assets
// Stamp assets with version.
use lithium\net\http\Media;
Media::attach('app', array('path' => dirname(LITHIUM_APP_PATH) . '/assets', 'prefix' => 'assets/v:' . PROJECT_VERSION_BUILD));
// Set default scope.
Media::scope('app');
// Render libary views in the app's layout only.
Media::type('default', null, array('view' => 'lithium\\template\\View', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => LITHIUM_APP_PATH . '/views/layouts/{:layout}.{:type}.php', 'element' => '{:library}/views/elements/{:template}.{:type}.php')));
/**
 * This filter is a convenience method which allows you to automatically route requests for static
 * assets stored within active plugins. For example, given a JavaScript file `bar.js` inside the
 * `li3_foo` plugin installed in an application, requests to `http://app/path/li3_foo/js/bar.js`
 * will be routed to `/path/to/app/libraries/plugins/li3_foo/webroot/js/bar.js` on the filesystem.
 * In production, it is recommended that you disable this filter in favor of symlinking each
 * plugin's `webroot` directory into your main application's `webroot` directory, or adding routing
 * rules in your web server's configuration.
 */
// use lithium\action\Dispatcher;
// use lithium\action\Response;