2014-04-04 173 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 

因此,對於這種應用路線將只需檢查哪個控制器需要被激活,功能的映射將通過上述過程完成。

希望能幫到