mvccore / ext-view-helper
MvcCore - Extension - View - Helper - abstract class code and interface support code to create more sofisticated view helpers with better setup and protected properties.
v5.3.0
2024-11-21 12:47 UTC
Requires
- php: >=5.4.0
- mvccore/mvccore: ^5.3
This package is auto-updated.
Last update: 2024-11-21 16:01:08 UTC
README
Abstract class code and interface support code to create more sofisticated view helpers with better setup and protected properties.
Installation
composer require mvccore/ext-view-helper
Example
Your custom primitive view helper code:
// located in `/App/Views/Helpers/FormatNumber.php` namespace App\Views\Helpers; class FormatNumber { public function FormatNumber ($number) { // $number = 1234.56; return number_format($number); // english notation - 1,234 } }
... could be more sofisticated with this package:
// located in `/App/Views/Helpers/FormatNumber.php` namespace App\Views\Helpers; class FormatNumber extends \MvcCore\Ext\Views\Helpers\AbstractHelper public function FormatNumber ($number) { // $number = 1234.56; if ($this->request->GetLang() == 'fr') { return number_format($number, 2, ',', ' '); // french notation: 1 234,56 } else { return number_format($number); // english notation: 1,234 } } }
Automaticly assigned protected properties
AbstractHelper::$view
as\MvcCore\View|\MvcCore\IView
AbstractHelper::$controller
as\MvcCore\Controller|\MvcCore\IController
AbstractHelper::$request
as\MvcCore\Request|\MvcCore\IRequest
AbstractHelper::$response
as\MvcCore\Response|\MvcCore\IResponse
Behaviour
- Your view helper will be created by static method
GetInstance()
as singleton with abstract classAbstractHelper
. - Everytime, when there will be rendered different view script (action view, layout view or sub-controller view), there will be called automatically method
AbstractHelper::SetView($view);
to setup view object or other objects inside helper to actual ones.