load() method doesn't work |
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 !
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);
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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.
You might want to look into new View Layouts also, and see if they are something you're interested in.
And the view parser :-)
https://codeigniter4.github.io/CodeIgnit...arser.html |
Welcome Guest, Not a member yet? Register Sign In |