Differences

This shows you the differences between two versions of the page.

Link to this comparison view

auto_load_splint [2019/05/31 17:26] (current)
Line 1: Line 1:
 +====== Auto-Loading Splints ======
  
 +Just as you specify resources such as libraries, helpers, models etc. to load automatically from the ''​application/​config/​autoload.php''​ file, you can as well load splint resources from this same file, provided that your loader is patched.\\
 +
 +The following Splint resources can be auto-loaded:​\\
 +
 +  * Libraries
 +  * Models
 +  * Helpers
 +  * Configs
 +  * Views 
 +
 +To auto load splints, open the ''​application/​config/​autoload.php''​ file and look for or create the associative key ''​splint''​ in the ''​$autoload''​ array.
 +
 +> If you are using the [[https://​github.com/​splintci/​sdk|Splint SDK]] as your Code Igniter distribution,​ you'll already have the associative key (''​splint''​) declared on the ''​$autoload''​ array at the bottom of the file.
 +
 +> Remember, ''​$autoload["​splint"​]''​ is intended to be an associative array of splints to auto-load. the key of each element will be the vendor and package name combination of the splint while it's corresponding value is an array of arguments. The arguments you would pass to the ''​$this->​load->​splint()''​ function when loading the splint from a controller.
 +
 +===== Auto-Loading Libraries =====
 +
 +<code php>
 +$autoload["​splint"​] = array("​vendor/​package_name"​ => array("​+Library",​ $params, $alias));
 +</​code>​
 +
 +The above will allow you use the library from anywhere with
 +
 +<code php>
 +$this->​alias->​method();​
 +</​code>​
 +
 +> Note the prefix character(''​+''​) for specifying the auto-loaded library class. See the notes on [[start#​load_prefixes|Load Prefixes]] to know more about it.
 +
 +=== Auto-Loading Models ===
 +
 +<code php>
 +$autoload["​splint"​] = array("​vendor/​package_name"​ => array("​*Model",​ $alias));
 +</​code>​
 +
 +The above will allow you use the model from anywhere with
 +
 +<code php>
 +$this->​alias->​method();​
 +</​code>​
 +
 +===== Auto-Loading Helpers =====
 +
 +<code php>
 +$autoload["​splint"​] = array("​vendor/​package_name"​ => array("​%helper",​ $alias));
 +</​code>​
 +
 +This will enable you call the functions declared in the helper from anywhere.
 +
 +===== Auto-Loading Configs =====
 +
 +<code php>
 +$autoload["​splint"​] = array("​vendor/​package_name"​ => array("​@config"​));​
 +</​code>​
 +
 +===== Auto-Loading Views =====
 +
 +<code php>
 +$autoload["​splint"​] = array("​vendor/​package_name"​ => array("​-view",​ $data));
 +</​code>​
 +
 +This will result in all pages your ''​Controllers''​ send back to browsers having the specified view.
 +
 +===== Conclusion =====
 +
 +Assuming we have 3 libraries to auto-load which are:
 +
 +  * zoey/​bootstrap
 +  * francis94c/​ci-preference
 +  * jonas/git
 +
 +We could auto-load them as follows.
 +
 +<code php>
 +$params = array();
 +$autoload["​splint"​] = array (
 +  "​zoey/​bootstrap" ​          => array("​+BootStrap",​ $params, "​bootstrap"​),​
 +  "​francis94c/​ci-preference"​ => array("​+CIPereferences",​ $params, "​prefs"​),​
 +  "​jonas/​git" ​               => array("​+Git",​ null, "​git"​) ​
 +)
 +</​code>​
 +
 +This will allow us to use these libraries from anywhere like below:
 +
 +<code php>
 +// zoey/​bootstrap
 +$bootstrap->​loadHeaders();​
 +// francis94c/​ci-preference
 +$prefs->​set("​open",​ true);
 +$prefs->​commit();​
 +// jonas/got
 +$git->​clone($url,​ $dir);
 +</​code>​
 +
 +===== NEXT =====
 +[[splint_loader|The Splint Loader]] => \\
 +
 +===== PREVIOUS =====
 +<= [[splint_object|Splint Object]]\\
 +
 +===== Other Topics =====
 +
 +[[splint_loader|The Splint Loader]]\\
 +[[library-install|Install a Splint Library]]\\
 +[[splint_production_server|Install Splint Libraries in Production]]\\