2017-25 © Pedro Peláez
 

zf-module zfc-current

Plugin and Helper for get current controller, action, route, request and much more

image

popov/zfc-current

Plugin and Helper for get current controller, action, route, request and much more

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 24 % Grown

The README.md

ZF2 Current Module

This plugin allow get current namespace, module, controller, action, route, router and request through Controller Plugin or View Helper., (*1)

Instalation

Add package to your composer.json, (*2)

{
    "require": {
        "popovsergiy/zfc-current": "dev-master"
    }
}

And update your vendors, (*3)

$ php composer.phar update popovsergiy/zfc-current

Don't forget Add 'Popov\Current' to config/application.config.php, (*4)

return [
    'modules' => [
        // ...
        'Popov\Current'
    ]
]    

Usage

This library has Controller Plugin and View Helper which allow simple access to main ZF2 varialbes., (*5)

Controller usage

namespace YourModule\Controller

use Zend\Mvc\Controller\AbstractActionController;

class PostController extends AbstractActionController {

  public function indexAction() {
    $this->current('controller'); // post - controller name in module.config.php
    $this->current('action'); // index
    $this->current('module'); // YourModule  
    $this->current('route'); // RouteMatch object  
    $this->current('request'); // Request object

    $this->current()->currentModule(\Other\Module\Model\Entity::class); // Other\Module
  }
}

View Usage

// your-module/post/index.phtml

Current controller : = $this->current('controller') ?>
Current action : = $this->current('action') ?>
Current module : = $this->current('module') ?>

url('default/id', [
    'controller' => $this->current('route')->getParam('controller'),
    'action' => $this->current('route')->getParam('action'),
    'id' => $this->current('route')->getParam('id'),
]);
// or
$current = $this->current();
$action = $this->url('default/id', [
    'controller' => $current('route')->getParam('controller'),
    'action' => $current('route')->getParam('action'),
    'id' => $current('route')->getParam('id'),
]);
?>

Tricks and tips

If you use forward plugin and need current (forward) param, next call return expected value, (*6)

$this->current()->getController()->getEvent()->getRouteMatch()->getParam('action');

In all other case you get real params that is in URL, (*7)

The Versions

09/07 2018

dev-master

9999999-dev

Plugin and Helper for get current controller, action, route, request and much more

  Sources   Download

MIT BSD-3-Clause

The Requires

  • php >=5.5

 

zf2 agere current

04/04 2018

0.2.0

0.2.0.0

Plugin and Helper for get current controller, action, route, request and much more

  Sources   Download

MIT

The Requires

  • php >=5.5

 

zf2 agere current

14/12 2016

0.1.0

0.1.0.0

Plugin and Helper for get current controller, action, route, request and much more

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5

 

zf2 agere current

23/06 2016

dev-dev

dev-dev

Plugin and Helper for get current controller, action, route, request and much more

  Sources   Download

BSD-3-Clause

The Requires

 

zf2 agere current