X
X
XenK2015-10-25 12:05:43
Phalcon
XenK, 2015-10-25 12:05:43

Phalcon, how to make the correct routing?

d62387cc99274feab5726d370fd8e532.PNG
You need to do the right routing so that, for example, if you go to site.ru/profile/1, data with id = 1 (name, age...) is shown. If you go to site.ru/profile/1/edit, you can edit your profile, respectively, if the user is authorized and this is his profile. If you simply go to site.ru/profile, then again, if the user is authorized, he was transferred to a personal account (for example: site.ru/profile/5). How and in what way is it better to implement everything?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Capito, 2015-10-26
@Capito

>> site.ru/profile/1

$router->addGet("/api/:controller/:int",
    array(
      "namespace" => 'ТутНаймспейсТвоегоКонтроллера', // Если не задан глобально дефолтный
      "controller" => 1,
      "action"     => 'show',
      "id"		 => 2
    ));

In the ProfileController controller:
public function showAction($id) {
// ...
// тут выводишь данные профиля       
}

$router->addGet("/api/:controller/:int/:action",
    array(
      "namespace" => 'ТутНаймспейсТвоегоКонтроллера', // Если не задан глобально дефолтный
      "controller" => 1,
      "action"     => 3,
      "id"		 => 2
    ));

In the ProfileController controller:
public function editAction($id) {
// тут делай че хочешь, форму наверное нада отобразить
        
}

Well, in general, everything is in this spirit. In general, this section in the dock is described in great detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question