CodeIgniter Forums
Using a library within a view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Using a library within a view (/showthread.php?tid=23074)



Using a library within a view - El Forum - 09-29-2009

[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


Using a library within a view - El Forum - 09-29-2009

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


Using a library within a view - El Forum - 09-29-2009

[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>



Using a library within a view - El Forum - 09-24-2010

[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.