We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

remove index in url

hi, i have a controller and is name 'item' ( url: item/index/1593 )

i want to show url like this: item/1593

actiually 1593 is Parametr.

my route is :

$publicResources = array( 'item' => array('index') );

foreach ($publicResources as $resource => $actions) { $acl->addResource(new Resource($resource), $actions); }

how can i do this ?

sry for bad type english .



Your code concerns the ACL, and not the routing :

To define an URL like item/1345, you can add a route like this :

$router = new Router();
//Define a route
        "controller" => "item",
        "action"     => "index",
        "id"     => 1

where id is the named parameter of type int

you can also use the short syntax :

$router->add("/item/{id:[0-9]+}", "Item::index");

you can then access the id parameter as follows:

class ItemController extends Controller{

    public function indexAction(){

        // Returns "id" parameter
        $id = $this->dispatcher->getParam("id");

For more details, see http://docs.phalcon.io/en/latest/reference/routing.html

edited Apr '15

Tanx jcheron :)