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 .



1.1k
Accepted
answer

Hi,

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
$router->add(
    "/item/:int",
    array(
        "controller" => "item",
        "action"     => "index",
        "id"     => 1
    )
);
...
$router->handle();

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.phalconphp.com/en/latest/reference/routing.html



2.4k
edited Apr '15

Tanx jcheron :)