0

I've this Url "backend/codici/view?id=1" and I want to hide the id, because I don't want to show it. It must be only "backend/codici". I try enabling Pretty Url but it doesn't work. This my config/web.php file:

'urlManager' => [
      'enablePrettyUrl' => true,
      'showScriptName' => false,
      'rules' => [],
],

What I have to do to solve it? thank you very much!!!!

Sfili_81
  • 2,377
  • 8
  • 27
  • 36
jackall90
  • 11
  • 4
  • 2
    How else will you identify view that should be displayed - without ID parameter? Perhaps you mean that you want to mask it e.g. replace `id=123` with something like `id=XYZMASKEID` .. ? – lubosdz Aug 31 '22 at 22:38
  • Check this [answer](https://stackoverflow.com/questions/34012312/rewrite-url-in-yii2) – Sfili_81 Sep 01 '22 at 12:35

1 Answers1

0

Scenario 1

Is there just one record of type codici? If yes, replace the CodiciController::actionIndex() method in order to instead of listing all codici records, load the one (Codici::findOne()) and render view file instead of index. Basically copy paste the content of actionView() but instead of load model by id, load the existing one.

I'm assuming default code generated by Gii for a codici table in your database.

Scenario 2

If there is more than one record, then you have 2 options:

  • to pass the ID via query string (default, like it is now)
  • use a POST request instead of GET request, the ID will not be shown in the URL, but it requires some magic in the link. Also note that a regular view page should not be requested via POST, but via GET.