【发布时间】:2014-04-04 00:52:33
【问题描述】:
我正在查看一个名为 Wall 的已配置模块:
return array(
'router' => array(
'routes' => array(
'wall' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/api/wall[/:id]',
'constraints' => array(
'id' => '\w+'
),
'defaults' => array(
'controller' => 'Wall\Controller\Index'
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'Wall\Controller\Index' => 'Wall\Controller\IndexController',
),
),
所以“路由器”数组的“默认”成员设置为值Wall\Controller\Index。所以Wall\Controller\Index 我认为它是一个命名空间,但我真的不明白为什么它这样设置的含义。控制器定义在IndexController.php:
<?php
namespace Wall\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class IndexController extends AbstractRestfulController
{
protected $usersTable;
public function get($username)
{
$usersTable = $this->getUsersTable();
$userData = $usersTable->getByUsername($username);
$wallData = $userData->getArrayCopy();
if ($userData !== false) {
return new JsonModel($wallData);
} else {
throw new \Exception('User not found', 404);
}
}
}
所以控制器中唯一接受参数的方法是 get 所以我不得不说这是访问 /wall/tusername 时调用的方法,但我不清楚路由是如何工作的。所以路由墙的默认设置为“Wall\Controller\Index”是什么意思?这是否意味着“默认值”中未声明“动作”?如果未声明“操作”,会发生什么行为?
感谢您的发帖。
【问题讨论】: