MvcCore - Extension - View - Helper
, (*1)
Abstract class code and interface support code to create more sofisticated view helpers with better setup and protected properties., (*2)
Installation
composer require mvccore/ext-view-helper
Example
Your custom primitive view helper code:, (*3)
// 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:, (*4)
// 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 class AbstractHelper
.
- 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.