Res::name() method just as
shown below:
<php?
Res::new()
->name('headers')
->url('some_css_url_1.css')
->url('some_css_url_2.css')
->url('some_js_url.js')
->name('footers')
->url('some_css_url_1.css')
->url('some_css_url_2.css')
->url('some_js_url.js')
->urlClose();
@res() directive
@res(':header') //import all declared header urls
<?= Res::import() ?> method similarly outside the template file. Only the urls in
the called group will be imported to the webpage rather than having to call them one after the other in multiple files.
While this is easy to use, one major issue could be that if we need a url from another group into a new group, we need to set the group name and url again.
If we happen to use the same url in multiple groups and the list is long, it may be difficult to manage a url
multiple times especially if we have to change the path of a file. In order to resolve this issue, version 2.0 provides new methods which helps to properly name urls
making it easier to manage all urls as deemed fit.
<php?
Res::new()
->name('headers')
->url('some_css_url_1.css')->named('css1') //set unique name
->url('some_css_url_2.css')->named('css2')
->url('some_js_url.js')->named('js1')
->name('footers')
->url('js_url_1.js')
->url('js_url_2.css')->named('js2')
->urlClose();
@recall('css1', 'css2', 'js2') //call files by unique name
Res::recall() method or the recall() helper function to achieve a similar response. While
the recall() function is similar to @recall() directive, the Res::recall()
is slightly different as it can only call a single unique name at a time.
<?php
Res::recall('css1'); //calling unique name returns a script or list of scripts
Res::recall('css1', true); //calling unique name returns an array of scripts
recall() makes this operation easier.
However, since the files are used within template files, the directive @recall() or @load() will at most times be used. The introduction of these
approaches even makes it easier to generate groups using defined names rather than their real path.
<php?
Res::new()
->name('headers')
->url('some_css_url_1.css')->named('css1')
->url('some_css_url_2.css')->named('css2')
->url('some_js_url.js')->named('js1')
->name('footers')
->url('js_url_1.js')
->url('js_url_2.css')->named('js2')
->bind('cssgroup', ['css1','css2'])
->bind('jsgroup', ['js1','js2'])
->urlClose();
@recall('cssgroup') //each script of specified group will be returned to the webpage.
bind() method's group name supplied as
the first argument must be unique name. The resource methods named(), bind() and
bindTo() all share the same unique storage space. This means that any name supplied in any of these
methods cannot be unique in another method of the same group although, the bindTo() method is slightly
different. This is shown below:
<php?
Res::new()
->name('headers')
->url('some_css_url_1.css')->named('css1')
->url('some_css_url_2.css')->named('css2')
->url('some_js_url.js')->named('js1')
->bindTo('headers')
->name('footers')
->url('js_url_1.js')
->url('js_url_2.css')->named('js2')
->bindTo('footers')
->bindTo('headers', ['js2'])
->bind('cssgroup', ['css1','css2'])
->bind('jsgroup', ['js1','js2'])
->urlClose();
bindTo() method works. The code structure is explained below: bindTo() is used immediately after a set of named urls, it binds
only the previously named urls into a new unique group. The new unique group name
has nothing to do with the one defined through the global name(). For example, the bindTo('headers') will
add all the previously named urls into the supplied unique name "headers" while in the case of
bindTo('footers') only the named url "js2" will be added to the new unique group name.
bindTo('headers', ['js2']) adds the url of "js2" to existing unique
group "headers"
bindTo() is used, all named urls before it will be added into the new group regardless of their parent groups.
Once the method is used, the previous named groups will be safely exited without affecting their unique names.
res/res.php file.
The main static files declaration have been moved to a more private directory core/res.php to remove visual noise.
"headers" and "footers" are reserved, more urls can be
added into them. This can be done by either using bindTo() for unique names or by using the name()
method for global namespace.
named(), bind() and bindTo(). The bindTo() can only
add more urls, it cannot redeclare an existing name unless the entire class is started on a strict mode using the urlOpen(true) method which entirely clears all previous declarations.