Differences

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

Link to this comparison view

splint_loader [2019/05/31 17:26] (current)
Line 1: Line 1:
 +====== Splint Loader ======
  
 +===== splint() function ===== 
 +
 +The splint loader function is accessed by
 +
 +<code php>
 +$this->​load->​splint();​
 +</​code> ​
 +
 +==== Loading a Splint Object ====
 +
 +<code php>​$this->​load->​splint($splint);</​code>​
 +
 +This will return a [[splint_object|Splint Object]].
 +
 +<code php>
 +$bootstrap = $this->​load->​splint("​zoey/​bootstrap"​);​
 +$data = array("​title"​ => "My Website"​);​
 +$bootstrap->​load->​view("​responsive_header",​ $data);
 +$bootstrap->​load->​view("​footer"​);​
 +</​code>​
 +==== Parameters For Libraries ====
 +<code php>​$this->​load->​splint($splint,​ $autoload, $params, $alias);</​code>​
 +
 +^ Parameter ​                         ^ Description ​              ^ Required ​                             ^ Examples ​         ^
 +| ''​splint''​ ''​(string)'' ​           | The name of the splint package to load or search from. If only this argument is supplied, the function will return a ''​[[splint_object|Splint Object]]''​ instead. | Yes | denver/​github,​ cynobit/​blogger |
 +| ''​autoload''​ ''​(string)/​(array)'' ​ | The ''​autoload''​ parameter specifies the ''​class''​ or resource to be loaded if supplied as a ''​string''​ (see [[start#​auto-load_prefixes|Auto-load Prefixes]] for more about this). To load multiple libraries or resources, supply an array of associative arrays of arrays. [[start#​load_multiple_libraries_resources|See an Example]]. | Yes |<code php>​$this->​load->​splint(
 +"​francis94c/​ci-prefeence", ​
 +"​+CIPreference",​
 +null, "​alias"​);</​code>​ |
 +| ''​params''​ ''​(array)''​ | an associative array of parameters. these are usually defined in the README file of any package you want to use | No | <code php>​$params = array("​key"​ => "​value"​);</​code>​ |
 +| ''​alias''​ ''​(string)''​ | The name of the resulting object from which features of the library are accessed. | No | <code php>​$this->​alias->​someMethod();</​code>​ |
 +
 +==== Parameters for Models ====
 +<code php>​$this->​load->​splint($splint,​ $model, $alias);</​code>​
 +
 +^ Parameter ​                         ^ Description ​                                           ^ Examples ​        ^
 +| ''​splint''​ ''​(string)'' ​           | The name of the splint package to load or search from. | denver/​github,​ cynobit/​blogger |
 +| ''​model''​ ''​(string)/​(array)'' ​ | The ''​model''​ parameter specifies the model ''​class''​ to be loaded. It must be prefixed with a ''​*''​ character to load the specified model. see [[start#​auto-load_prefixes|Auto-load Prefixes]] for more about this). |<code php>​$this->​load->​splint("​francis94c/​ci-preference", ​
 +"​*CIModel",​ "​ci_model"​);</​code>​ |
 +| ''​alias''​ ''​(string)''​ | The name of the resulting object from which features of the model are accessed. | <code php>​$this->​alias->​someMethod();</​code>​ |
 +
 +==== Parameters For Configs ====
 +<code php>​$this->​load->​splint($splint,​ $config);</​code>​
 +
 +^ Parameter ​                         ^ Description ​                                           ^ Examples ​          ^
 +| ''​splint''​ ''​(string)'' ​           | The name of the splint package to load or search from. | denver/​github,​ cynobit/​blogger | 
 +| ''​config''​ ''​(string)'' ​           | The name of the config file to load.                   | ''"​server_config"''​|
 +
 +==== Parameters For Views ====
 +<code php>​$this->​load->​splint($splint,​ $view);</​code>​
 +
 +^ Parameter ​                         ^ Description ​                                           ^ Examples ​          ^
 +| ''​splint''​ ''​(string)'' ​           | The name of the splint package to load or search from. | denver/​github,​ cynobit/​blogger | 
 +| ''​config''​ ''​(string)'' ​           | The name of the view to load.                   | ''"​server_config"''​|
 +
 +==== Parameters For Helpers ====
 +<code php>​$this->​load->​splint($splint,​ $helper);</​code>​
 +
 +^ Parameter ​                         ^ Description ​                                           ^ Examples ​          ^
 +| ''​splint''​ ''​(string)'' ​           | The name of the splint package to load or search from. | denver/​github,​ cynobit/​blogger | 
 +| ''​config''​ ''​(string)'' ​           | The name of the helper to load.                   | ''"​server_config"''​|
 +
 +===== bind() function =====
 +
 +An alternative to creating a [[splint_object|Splint Object]] is the ''​bind()''​ function.
 +
 +Ideally, a Splint object is meant to be used in a situation where you need to load multiple resources from one package (where supplying the full range of arguments to the ''​splint()''​ function could be strenuous). The Splint object is a representation the package, that lets you load resources as you wish by specifying the package once.\\
 +
 +<code php>
 +$this->​load->​bind($splint,​ $bind);
 +</​code>​
 +
 +==== Parameters ====
 +
 +^ Parameter ​                         ^ Description ​                         ^ Required ​                 ^ Examples ​         ^
 +| $splint(string) ​                    | The splint package to load.     | Yes             | ''​zoey/​bootstrap''​ |
 +| $bind (null object) ​            | The object that the specified ''​$splint''​ should be bound to. you do not need to declare this argument prior to calling the function. If omitted, the function will return the Splint object instead. | No | ''​$this->​load->​bind(''​zoey/​bootstrap'',​ $bootstrap)''​ |
 +
 +For example, the ''​zoey/​bootstrap''​ package could be loaded with then ''​bind''​ function and used as follows.
 +
 +<code php>
 +$this->​load->​bind("​zoey/​bootstrap",​ $bootstrap);​
 +$data = array("​title"​ => "My Website"​);​
 +$bootstrap->​load->​view("​responsive_header",​ $data);
 +$bootstrap->​load->​view("​footer"​);​
 +
 +// OR
 +
 +$bootstrap = $this->​load->​bind("​zoey/​bootstrap"​);​
 +$data = array("​title"​ => "My Website"​);​
 +$bootstrap->​load->​view("​responsive_header",​ $data);
 +$bootstrap->​load->​view("​footer"​);​
 +</​code>​
 +
 +===== package() function =====
 +This function allows you to specify a package name only that allows Splint to load resources specified automatically by the vendor of the Splint package.\\
 +
 +<code php>
 +$this->​load->​package($splint);​
 +</​code>​
 +
 +For instance, if a package'​s ''​splint.json''​ descriptor file contains the below ''​autoload''​ key defined along side other keys as follows.
 +
 +<code json>
 +{
 +  "​....":​ "​............",​
 +  "​autoload":​ {
 +    "​libraries"​ : [
 +      ["​Class",​ "​alias"​]
 +    ]
 +  }
 +}
 +</​code>​
 +
 +If the name of the package is for instance, ''​zoey/​bootstrap'',​ a call to the ''​package()''​ function with the package name passed as an argument will automatically load the class with the alias as defined in the descriptor. See the below example.
 +
 +<code php>
 +$this->​load->​package("​zoey/​bootstrap"​);​
 +$this->​alias->​someMethod();​
 +</​code>​
 +
 +The resources that could be auto-loaded by vendors include:
 +
 +  * Libraries
 +  * Models
 +  * Helpers
 +  * Configs
 +===== NEXT =====
 +[[update_splint|Updating Splint Client]] => \\
 +
 +===== PREVIOUS =====
 +
 +<= [[auto_load_splint|Auto-Loading Splints]]\\
 +
 +===== Other Topics =====
 +
 +[[auto_load_splint|Auto-Loading Splint]]\\
 +[[developer:​splint_json|Splint Package Descriptor]]