S
S
SteveJ422021-02-01 10:57:02
Yii
SteveJ42, 2021-02-01 10:57:02

How do routes work in Yii2?

Hello! Started learning the Yii2 framework based on the lessons of Andrey Kudlay.
The lecturer simply created a controller and a method returning a string and made a request in the address bar for this controller and its method, let's say test / index and the program returned to him the string that he wrote in the method of this class.
Why did he not write this route to the routes.php file before doing all this, and how did Yii2 understand that he needed this particular class and method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Bay, 2021-02-01
@SteveJ42

Yii2 does not have routes like Laravel. offtopic: If by the way you have experience in Laravel, I see no reason to go to Yii2.
Routes can take the following format:

ControllerID/ActionID

or the following format if the controller belongs to a module:
ModuleID/ControllerID/ActionID

The UrlManager component in the config allows you to set aliases for routes.
https://github.com/yiisoft/yii2/blob/master/docs/g... here in detail

A
Alexander Lykasov, 2021-02-01
@lykasov-aleksandr

I don’t know how it was done in this lesson, but in Yii (basic project) in the web.php config in the UrlManager settings, the default route is set:

'<controller:>/<action:>' => '<controller>/<action>',

Which is used if nothing else was added.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question