Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2015 00:46
Show Gist options
  • Save anonymous/370985358ba7dbf8ee24 to your computer and use it in GitHub Desktop.
Save anonymous/370985358ba7dbf8ee24 to your computer and use it in GitHub Desktop.
<h1>Post</h1>
<?php Zend\Debug\Debug::dump($this->categories); ?>
<?php
return array(
'controllers' => array(
'invokables' => array(
'market-index-controller' => 'Market\Controller\IndexController',
'market-view-controller' => 'Market\Controller\ViewController',
),
'factories' => array(
'market-post-controller' => 'Market\Factory\PostControllerFactory',
),
),
'controller_plugins' => array(
'invokables' => array(
'newDate' => 'Market\Controller\Plugins\NewDate',
),
),
'router' => array(
'routes' => array(
'market' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/market',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
//'__NAMESPACE__' => 'Market\Controller',
'controller' => 'market-index-controller',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'Market' => __DIR__ . '/../view',
),
),
);
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/Market for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Market\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Filter\HtmlEntities;
use Zend\View\Model\ViewModel;
class PostController extends AbstractActionController
{
protected $categories;
/**
* @return the $categories
*/
public function getCategories()
{
return $this->categories;
}
/**
* @param field_type $categories
*/
public function setCategories($categories)
{
$this->categories = $categories;
}
public function indexAction()
{
$viewModel = new ViewModel(array('categories' => $this->getCategories()));
return $viewModel;
}
}
<?php
namespace Market\Factory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Market\Controller\PostController;
class PostControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $sl)
{
$sm = $sl->getServiceLocator();
$controller = new PostController();
$controller->setCategories($sm->get('application-categories'));
return $controller;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment