This is an outdated version of PHPasap. Please visit for the latest version.

HTML Helper for handling Assets

Instead of hardcoding the absolute URL or using a relative URL for loading a resource (js, css and image file) you are strongly encouraged to use below methods as needed. These will take care of prepending the base URL as needed so that you don't have to worry while deploying your application from development to production server.

Adding a stylesheet

echo HTML::style("assets/css/style.css");
//assets folder is in project root and not necessarily web root
Above tag will produce <link rel="stylesheet" href="http://your" >. PHPasap will prepend the base url to the provided url path.

Adding an external stylesheet

echo HTML::style("");

The syntax for loading an external stylesheet is same as for loading a local one. There is no magic here. Whenever there is a http:// or https:// PHPasap assumes that provided path is an absolute path and hence doesn't prepend the base url to the provided path.

However in some case you may want to explicitly specify if the resource is local or external instead of letting PHPasap do the guessing. Below is a particular use case

echo HTML::style("//", true);

In above example a boolean true in second parameter tells PHPasap that this is an external resource. The default value for this parameter is boolean false. By default PHPasap will assume the resource is a local one if provided path doesn't begin with http:// or https://.

Adding a script

echo HTML::script("assets/js/common.js");
//assets folder is in project root and not necessarily web root

Usage is same as HTML::style() above

Adding an external script

echo HTML::script("");

echo HTML::script("//", true);
//by giving true in second param we are telling PHPasap this is external resource. See HTML::style() for more info

Creating a link

echo HTML::link("news/all", "All News");

The above will produce <a href="">All News</a>

Creating an external link

echo HTML::link("", "Perials Website");
//<a href="">Perials Website</a>

Whenever the provided url path starts with a http:// or https:// PHPasap assumes it as a external resource and doesn't prepend base url to it.

Just as with HTML::style() and HTML::script() passing second param as true tells PHPasap to treat this as external resource irrespective of what the url passed in first param is.

echo HTML::link("//", "Perials Website", true);
//<a href="">Perials Website</a>

Adding custom attributes

The optional third param for HTML::style() and HTML::script() and fourth param for HTML::link() is an associative array. Anything in this array will be added as a string of attr="value" to the respective resource tag. See below examples

echo HTML::link("news/all", "All News", false, ["class"=>"anchor", "attr2"=>"value2"]);
//<a href="" class="anchor" attr2="value2">All News</a>

echo HTML::style("assets/css/style.css", false, ["attr1"=>"value1", "attr2"=>"value2"]);
//<link rel="stylesheet" href="" attr1="value1" attr2="value2" >

echo HTML::script("assets/js/common.js", false, ["attr1"=>"value1", "attr2"=>"value2"]);
//<script src="" attr1="value1" attr2="value2"></script>

Creating urls

echo HTML::url("news/all");

Above code will produce

PHPasap doesn't support external url (say as you are better off hardcoding it as it is.