I'm looking at a module called Wall that is configured:
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',
),
),
So the 'defaults' member of the 'router' array is set to the value Wall\Controller\Index
. So Wall\Controller\Index
I take to be a namespace but I really don't understand the meaning of why its set that way. The controller is defined in 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);
}
}
}
So the only method in the controller that takes a parameter is get so I have to say that is what is being called when one visits /wall/tusername but it is not clear to me how the route works. So the defaults for the route wall is set to "Wall\Controller\Index" what does that mean? Does it mean anything that 'action' is not declared in 'defaults'? What is the behavior if 'action' is not declared?
Thank you for posting.