Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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

http://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



16.8k
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 http://yourapp.com/login Phalcon will fire indexAction in LoginController
  • if you visit page http://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.