summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Advanced/Assets.page
diff options
context:
space:
mode:
authorxue <>2006-01-27 04:23:17 +0000
committerxue <>2006-01-27 04:23:17 +0000
commit35ccbf642e8d189558e795a87005513e456d9a5d (patch)
tree20b5bc968e66ff9691f4cb65cb41dc11e87f8e75 /demos/quickstart/protected/pages/Advanced/Assets.page
parent5e6e30fce9e99ec8704bf6700898572cf0f9c1e4 (diff)
Added assets section to quickstart tutorial.
Diffstat (limited to 'demos/quickstart/protected/pages/Advanced/Assets.page')
-rw-r--r--demos/quickstart/protected/pages/Advanced/Assets.page57
1 files changed, 57 insertions, 0 deletions
diff --git a/demos/quickstart/protected/pages/Advanced/Assets.page b/demos/quickstart/protected/pages/Advanced/Assets.page
new file mode 100644
index 00000000..857da3a1
--- /dev/null
+++ b/demos/quickstart/protected/pages/Advanced/Assets.page
@@ -0,0 +1,57 @@
+<com:TContent ID="body" >
+
+<h1>Assets</h1>
+<p>
+Assets are resource files (such as images, sounds, videos, CSS stylesheets, javascripts, etc.) that belong to specific component classes. Assets are meant to be provided to Web users. For better reusability and easier deployment of the corresponding component classes, assets should reside together with the component class files . For example, a toggle button may use two images, stored in file <tt>down.gif</tt> and <tt>up.gif</tt>, to show different toggle states. If we require the image files be stored under <tt>images</tt> directory under the Web server document root, it would be inconvenient for the users of the toggle button component, because each time they develop or deploy a new application, they would have to manually copy the image files to that specific directory. To eliminate this requirement, a directory relative to the component class file should be used for storing the image files. A common strategy is to use the directory containing the component class file to store the asset files.
+</p>
+<p>
+Because directories containing component class files are normally inaccessible by Web users, PRADO implements an asset publishing scheme to make available the assets to Web users. An asset, after being published, will have a URL by which Web users can retrieve the asset file.
+</p>
+
+<h2>Asset Publishing</h2>
+<p>
+Asset publishing is managed by the <tt>System.Web.UI.TAssetManager</tt> module. By default, all published asset files are stored under the <tt>[AppEntryPath]/assets</tt> directory, where <tt>AppEntryPath</tt> refers to the directory containing the application entry script. Make sure the <tt>assets</tt> directory is writable by the Web server process. You may change this directory to another by setting the <tt>BasePath</tt> and <tt>BaseUrl</tt> properties of the <tt>System.Web.UI.TAssetManager</tt> module.
+</p>
+<p>
+PRADO provides several methods for publishing assets or directories containing assets:
+</p>
+<ul>
+<li>In a template file, you can use <a href="?page=Configurations.Templates2#at">asset tags</a> to publish assets and obtain their URLs. Note, the assets must be relative to the directory containing the template file.</li>
+<li>In PHP code, you can call <tt>TControl::getAsset($relativePath)</tt> to publish an asset and get its URL. The asset file or directory must be relative to the directory containing the control class file.</li>
+<li>If you want to publish an arbitrary asset, you need to call <tt>TAssetManager::publishFilePath($path)</tt>.</li>
+</ul>
+<p>
+BE AWARE: Be very careful with assets publishing, because it gives Web users access to files that were previously inaccessible to them. Make sure that you do not publish files that do not want Web users to see.
+</p>
+
+<h2>Performance</h2>
+<p>
+PRADO uses caching techniques to ensure the efficiency of asset publishing. Publishing an asset essentially requires file copy operation, which is expensive. To save unnecessary file copy operations, <tt>System.Web.UI.TAssetManager</tt> only publishes an asset when it has a newer file modification time than the published file. When an application runs under the <tt>Performance</tt> mode, such timestamp checkings are also omitted.
+</p>
+<p>
+ADVISORY: Do not overuse asset publishing. The asset concept is mainly used to help better reuse and redistribute component classes. Normally, you should not use asset publishing for resources that are not bound to any components in an application. For example, you should not use asset publishing for images that are mainly used as design elements (e.g. logos, background images, etc.) Let Web server to directly serve these images will help improve the performance of your application.
+</p>
+
+<h2>A Toggle Button Example</h2>
+<p>
+We now use the toggle button example to explain the usage of assets. The control uses two image files <tt>up.gif</tt> and <tt>down.gif</tt>, which are stored under the directory containing the control class file. When the button is in <tt>Up</tt> state, we would like to show the <tt>up.gif</tt> image. This can be done as follows,
+<com:TTextHighlighter CssClass="source">
+class ToggleButton extends TWebControl {
+ ...
+ protected function addAttributesToRender($writer) {
+ ...
+ if($this->getState()==='Up') {
+ $url=$this->getAsset('up.gif');
+ $writer->addAttribute('src',$url);
+ }
+ ...
+ }
+ ...
+}
+</com:TTextHighlighter>
+In the above, the call <tt>$this->getAsset('up.gif')</tt> will publish the <tt>up.gif</tt> image file and return a URL for the published image file. The URL is then rendered as the <tt>src</tt> attribute of the HTML image tag.
+</p>
+<p>
+To redistribute <tt>ToggleButton</tt>, simply pack together the class file and the image files. Users of <tt>ToggleButton</tt> merely need to unpack the file, and they can use it right away, without worrying about where to copy the image files to.
+</p>
+</com:TContent> \ No newline at end of file