phalconphp路由并将postfix添加到操作中

时间:2014-04-08 08:37:37

标签: php phalcon

我想添加到phalconphp路由规则。当方法是POST然后调用控制器x,操作x +后postfix + params

$router->addPost('/:action/:params',['controller'=>'print','action'=>1."Post",'params'=>2]);

$router->addPost('/:action/:params',['controller'=>'print','action'=>str_replace(1,1.'Post',1),'params'=>2]);

但它不起作用。有什么想法解决?

1 个答案:

答案 0 :(得分:1)

只是为了清楚看:

在路由器中:

$router->add('/:action/:params',
            ['controller'=>'controllerName',
             'action'=>1,
             'pa‌​rams'=>2])
       ->via(['POST'])
       ->convert('action',
                  function($action){ 
                      return $action.'Post'; 
                  });

更多信息@docs:

http://docs.phalconphp.com/en/latest/reference/routing.html#http-method-restrictions

// This route will be matched if the HTTP method is POST or PUT
$router->add("/products/update")->via(array("POST", "PUT"));

转换允许在将路径参数传递给调度程序之前自由转换路径参数,以下示例说明如何使用它们:

//The action name allows dashes, an action can be: /products/new-ipod-nano-4-generation
$router
    ->add('/products/{slug:[a-z\-]+}', array(
        'controller' => 'products',
        'action' => 'show'
    ))
    ->convert('slug', function($slug) {
        //Transform the slug removing the dashes
        return str_replace('-', '', $slug);
    });