Tatter\Menus basics |
I am trying to use Tatter\Menus and have some very basic questions. I installed Tatter\Menus via Composer at /vendor/tatter and can't figure out how to get the example menu working, MainMenu.php.
Where should I put MainMenu.php - in app/Views? Or somewhere else? Documentation says "Since Menu is Stringable it can be used in your view or layout files as is. ". If I create a view (eg, TatterExampleView.php), I don't understand how to access MainMenu in the view file to display the menu? I looked at the Spatie page to see if it had any additional guidance and did not see anything. I really appreciate the work that was done to provide this library. Code: <? php
MainMenu is a PHP class. You can put anywhere if the CI4 autoloader can autoload it.
That is you must respect PSR-4. For example, app/Menus/MainMenu.php And you can instantiate it and convert to string. PHP Code: $mainMenu = (string) new \App\Menus\MainMenu(); PHP Code: echo new \App\Menus\MainMenu() But Tatter\Menus has a controller filter. It seems using it is easier. https://github.com/tattersoftware/codeig...#deploying
12-27-2021, 04:07 AM
(This post was last modified: 12-27-2021, 05:47 AM by dm1. Edit Reason: Added log file contents ) (12-26-2021, 05:06 PM)kenjis Wrote: MainMenu is a PHP class. You can put anywhere if the CI4 autoloader can autoload it.Thank you for the feedback. When I put it in app/Menus and instantiate it in a simple controller, I get an error exception PHP Code: ErrorException #64 Looking at the the Files tab in the debugger, I don't see multiple instances of MainMenu being loaded. Do you have any suggestions on how to troubleshoot this? Code: <?php Code: <?php
You need learn about PHP namespaces and PSR-4.
https://www.php.net/manual/en/language.n...ionale.php https://www.php-fig.org/psr/psr-4/
Thanks for the reading recommendations which I read. I looked at all the classes loaded in the app, grepped the directory for MainMenu, and do not see how Tatter\Menus\MainMenu could already be in use.
You have the class Tatter\Menus\MainMenu in somewhere and it seems it is already autoloaded.
And the namespace in app/Menus/MainMenu.php is incorrect. // app/Menus/MainMenu.php namespace Tatter\Menus; |
Welcome Guest, Not a member yet? Register Sign In |