我需要你的建议。我需要在 Apigility 生成的 RPC 样式 API 控制器中创建多个操作。我需要如何进行路由,以使其像在普通 zend 应用程序中一样工作。
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',/*I need flexible route like this one*/
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
Apigility 生成的代码是:
<?php
namespace TestAPI\V1\Rpc\Test;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
class TestController extends AbstractActionController
{
public function TestAction()
{
/*Added by myself*/
return new JsonModel(array(
'id' => 'test',
));
}
}
并以这种方式生成路由:
'controllers' => array(
'factories' => array(
'TestAPI\\V1\\Rpc\\Test\\Controller' => 'TestAPI\\V1\\Rpc\\Test\\TestControllerFactory',
),
),
'zf-rpc' => array(
'TestAPI\\V1\\Rpc\\Test\\Controller' => array(
'service_name' => 'test',
'http_methods' => array(
0 => 'GET',
),
'route_name' => 'test-api.rpc.test',
),
),
谢谢您的帮助!