Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading View Page In Library In Codeigniter

In my codeigniter i created a library in library folder.I want to load view pages in that library.How can i do this?

This is my code:

$this->load->view('view_page');

But when iam using this code i get an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_theme_lib::$load

Filename: libraries/theme_lib.php

Line Number: 9

What is the problem in mycode?

In Line number 9 in library the code is :

$this->load->view('view_page');
like image 779
Mas User Avatar asked Mar 01 '26 20:03

Mas User


1 Answers

To do what you're trying to do you need to get an instance of CI, and use that.

e.g.

$CI =& get_instance();

Within your library functions you could then use this variable to load the view:

$CI->load->view('view_page'); 

I would question though why you want to call a view, in the form that you have done, within a library. I suspect that you would be better to get the view call to return data (setting the 3rd parameter 'true') and then have your library return the display data to the controller.... Your approach seems messy, but then I have no idea what your library is trying to do.....

like image 197
Paul Campbell Avatar answered Mar 04 '26 11:03

Paul Campbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!