![]() |
load() method doesn't work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: load() method doesn't work (/showthread.php?tid=75193) |
load() method doesn't work - blaudroid - 01-08-2020 Hello there, since 1 week i started to get into the whole MVC World. And because my understanding of it equals null i was unsuccessful with CakePHP, Symfony or Laravel. Then i found the Codeigniter. I was experimenting with Routing and AJAX and Controllers and now i want to make myself a template in the Views folder. I tried to include the so called header.php and footer.php in my home.php page but i doesn't work. After some research i found out that in Codeigniter you can't just do an include like in conventional php. After another research i found a way to do it but my Codeigniter seems to not recognize the method i am using although for everyone else works without for them to do anything. My Code looks like this: PHP Code: <?php namespace App\Controllers; This call $this->load seems not to be existent. My PHPStorm throws me an error everytime i click on it. ![]() I am stuck and i don't know how can i go further. I have to mention that when i installed the Codeigniter Framework i just downloaded it and extracted it in my project folder as mentioned in the Docs. Then i followed the docs to finish setting it up. But somehow i think something is missing. And whenever i try to install it composer it just doesn't run, my powershell is stuck on an empty line. When i run this code my website just gives me the standard CI Whoops! Error. Thank you ! RE: load() method doesn't work - maxxd - 01-08-2020 You're mixing versions 3 and 4. PHP Code: $this->load->view('your-view', $data); is CodeIgniter 3. In CI4, use PHP Code: echo view('your-view', $data); RE: load() method doesn't work - InsiteFX - 01-09-2020 Because you are doing it wrong, there is no load view anymore. PHP Code: <?php namespace App\Controllers; That's how you do it now. RE: load() method doesn't work - blaudroid - 01-09-2020 Thank you very much ! I was looking in stackoverflow the whole time but i forgot that i was starting with CI 4 and not CI 3 and that the posts are outdated. Now i did it this way to save some time. Controller/Home.php PHP Code: <?php namespace App\Controllers; Controller/BaseController PHP Code: public function viewTemplate($viewName, $headerData = [], $footerData = [], $viewData = []) Now it works great. RE: load() method doesn't work - kilishan - 01-09-2020 You might want to look into new View Layouts also, and see if they are something you're interested in. RE: load() method doesn't work - littlej - 01-10-2020 And the view parser :-) https://codeigniter4.github.io/CodeIgniter4/outgoing/view_parser.html |