2014-04-04 175 views
1

我在寻找一个叫墙模块,配置:Zend Framework路由配置。 AbstractRestfulController

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); 
     } 
    } 
} 

所以,需要一个参数控制的唯一方法就是让所以我不得不说这就是被称为当一个访问/幕墙/ tusername,但目前尚不清楚对我来说路线是如何工作的。因此,路由墙的默认设置为“Wall \ Controller \ Index”,这是什么意思?这是否意味着任何'行动'没有在'默认'中声明?如果“行动”没有被宣布,那么行为是什么?

谢谢发布。

回答

2

休息,充分应用会有定义的任何行动,你可以看到,它已经扩展AbstractRestfulController而不是AbstractActionController

RestfulController会像这样:

When you call the URL with POST parameters then it will map to Create method, 
If you call with GET parameters it will map to GET or GETList method 
same as Delete->Delete and PUT -> Update 

因此,对于这种应用路线将只需检查哪个控制器需要被激活,功能的映射将通过上述过程完成。

希望能帮到