我尝试使用 AbstractRestfulController。我创建控制器类:
class MyController extends AbstractRestfulController{
public function getList(){
$data = array();
return new JsonModel(array(
'data' => $data,
));
}
public function get($id){
$data = array();
return new JsonModel(array(
'data' => $data,
));
}
public function create($data){
$data = array();
return new JsonModel(array(
'data' => $data,
));
}
public function update($id, $data){
$data = array();
return new JsonModel(array(
'data' => $data,
));
}
public function delete($id){
$data = array();
return new JsonModel(array(
'data' => $data,
));
}
}
和路由:
return array(
'router' => array(
'routes' => array(
'mylink' => array(
'type' => 'Segment',
'options' => array(
'route' => '/mylink[/:id]',
'constraints' => array(
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'MyModule\Controller\My',
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'MyModule\Controller\My' => 'MyModule\Controller\MyController',
),
),
'view_manager' => array(
'strategies' => array(
'ViewJsonStrategy',
),
),
);
但是当用户调用错误的方法或错误的 id 或其他任何东西时会发生什么?我想自己处理。怎么做?