Using a library within a view

#1
[eluser]Unknown[/eluser]
Hello all

Is it possible to load and use a library within a view.
I have a class which has a number of functions that do common tasks, such as building a select tag from an array.

If I load the library in the view with $this->load->library('htmllib') I don't get any error, but as soon as I reference the class with $this->htmllib->test() I get Undefined property: CI_Loader::$htmllib.

If I load the library within the controller and try to call of the functions all is ok, however as the purpose of the class is to deal with rendering html elements (in this case a select) I would like to keep this in the view.

Thanks in advance for any info / advise on this.

Andrew

#2
[eluser]kurucu[/eluser]
I pass some libraries into the view by reference, you could try that.

#3
[eluser]Colin Williams[/eluser]
I do what kurucu does when necessary

Code:
$data['pagination'] =& $this->pagination;
$this->load->view('results', $data);

In view:

Code:
<div>&lt;?php print $pagination->create_links() ?&gt;</div>

#4
[eluser]wortell[/eluser]
[quote author="Colin Williams" date="1254271933"]I do what kurucu does when necessary

Code:
$data['pagination'] =& $this->pagination;
$this->load->view('results', $data);

In view:

Code:
<div>&lt;?php print $pagination->create_links() ?&gt;</div>
[/quote]


Hmmm will this work with modules? I assume it should...

sidenote:
i use (ahem! sorry William), Phil's Template Library, only cuz it works seemlessly with HMVC and the updated MS/ME combined platform, etc, yadda yadda... but it should work irregardless of the templating system used....

furthermore:
tossing the =& reference of the object is quite ingenious... as this isn't discussed in a lot of places.

i'm just hoping it'll work on CI2.0+ME/MS5.3+, etc...

that's the ult. question.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.