A
A
Andrey2020-01-25 18:34:44
Yii
Andrey, 2020-01-25 18:34:44

The logic of your own routing?

Kind. I really wanted to experiment with my own CMS, and how everything works ... I read a lot, but after all the posts my head went round.
So there is YII2. Everything is standard.
There is a page table. ( ID, Content, Url ).
Created action in SiteController

public function actionParseurl( $path = 'nothing') {
      print_r( YII::$app->request->get() );
      echo '<hr style="border:0px; border-top: 1px dotted #ccc;">';

      if ( tPages::pageExists( $path ) ) { // Проверка на существование страницы
        return tPages::getPage( $path ); // Получение CONTENT и показ на экране.
      } else {
        return tPages::getPage( 'error' ); // Иначе показать ошибку (404)
      }
    }

added to the rules in the URL Manager:
'rules' => [
              '/<path:\w+>' => 'site/parseurl',
            ],

In 2 words. All requests are passed to ParseUrl and processed there.
And now I sit and think, have I implemented the routing logic correctly? And if not, then what? And where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-01-25
@skobanev


And now I sit and think, have I implemented the logic correctly?

Wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question