![]() |
How to call member functions within a class? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to call member functions within a class? (/showthread.php?tid=1518) |
How to call member functions within a class? - lexxtoronto - 03-17-2015 This is my original code: Code: Then I took out first two lines and put them in a separate function with the purpose of lessen lines of code and to try calling a member function. Code: private function load_head_page() And then: Code: else But it's giving me a fatal error saying header.php is undefined... RE: How to call member functions within a class? - logsdon - 03-17-2015 Can you paste the full error here? If your header.php is in the right folder structure to be found, maybe it's the $page variable in your load_head_page that is undefined and the error trace is just near the included header.php file. RE: How to call member functions within a class? - lexxtoronto - 03-17-2015 (03-17-2015, 11:48 AM)logsdon Wrote: Can you paste the full error here? If your header.php is in the right folder structure to be found, maybe it's the $page variable in your load_head_page that is undefined and the error trace is just near the included header.php file. Oh, ok so I guess Im calling load_head_page() correctly? That's what I was worried about. Thank you. RE: How to call member functions within a class? - lexxtoronto - 03-17-2015 The code works only if I include $this->load->helper('url'); in all functions one by one, but it doesnt work when I include it in the constructor like this: Code: function _construct() RE: How to call member functions within a class? - lexxtoronto - 03-17-2015 Solved, was using a single underscore instead of a double one.. duh.. RE: How to call member functions within a class? - silentium - 03-17-2015 May I suggest another, imo, a bit simpler and cleaner solution for you. Instead of breaking out the view loading of the header and page, just set the footer template name in a variable. Start by setting a default template, the regular footer used on all pages except contact us page. If the page is contact us, we just change the footer template variable to what footer we want to load. Here is an example PHP Code: public function view($page = "index") Also, just a small note, you don't need to include .php file ending. RE: How to call member functions within a class? - lexxtoronto - 03-18-2015 Ah, that's a useful tip, thank you |