Usage
Passing arguments to the view
To make your url more dynamic you can pass arguments to your view via the url, and it's very simple:
You just need to change your pattern to look like this:
<?php
/**In the file app/HelloLimpid/Config/routes.php**/
return [
'myview_route' => [ //--your route's name
'pattern' => '/my-view/%argument', //--the pattern that will be displayed in the url input of the browser
'command' => 'HelloLimpid_Default:myview', //---and the command that will be executed
], ]
By adding the character "%" to the pattern, Limpid will know that the string argument is a dynamic variable and can be anything
which means if you write something like this in the url /my-view/something Limpid will not throw a NotFoundException and will consider something a string and
inject it to your command in the controller, so you your command will look like this:
namespace app\HelloLimpidModule\Controller; use framework\core\Controller\AppController; class DefaultController extends AppController { /** * My first command command * As you can see you calld function should end with the word "Command" * so Limpid can recognize it, and also to your code clear ;) */ public function myviewCommand($argument){ $this->paintView('HelloLimpid:app.html.twig'); } }
After that you can do whatever you want with this variable or pass it to your view like this:
/** * My first command command * As you can see you called function should end with the word "Command" * so Limpid can recognize it, and also to your code clear ;) */ public function myviewCommand($argument){ $this->paintView('HelloLimpid:app.html.twig', array( 'arg' => $argument )); }
And this how to call the variable "arg" in your view:
<!--In your file app.html.twig--> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{% block page_title %}{% endblock %}</title> </head> <body> {# calling the argument inside a Twig view #} This is my argument: {{ arg }} {% block body %}{% endblock %} {% block js %}{% endblock %} </body> </html>