We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

URL problem

hi, i have some problem about my URL, because everytime i jump to the index of my view the URL look something like this

https://localhost:8080/project/login/index

what i want to do is that in every index on my view the

/index

on URL will not show.

thnk you in advance



26.3k
Accepted
answer

Have you built any your own routes? What I think is that you need to define your own route.

My proposition for your router:


$router->add("/:controller",array(
  'module' => 'yourmodulename', //delete this line if your app is single module
  'action' => 'index',
  'controller' => 1,
))->setName("your_route_name");

With the above code:

  • if you visit page https://yourapp.com/login Phalcon will fire indexAction in LoginController
  • if you visit page https://yourapp.com/home Phalcon will fire indexAction in HomeController

Then in your views you can build URLs like this:


echo $this->url->get(array(
  "for" => "your_route_name",
  "controller" => "login",
)); //it will return "/login"

echo $this->url->get(array(
  "for" => "your_route_name",
  "controller" => "home",
)); //it will return "/home"

I am quite a beginner so there might be some other better solutions.