In this post I will show you how to create a custom view helper in ZF2, writing custom view helper in zf2 is very easy thank to zf2 authors.
Here in this example i am goanna create StaticFileVersioning Module, you can place this module in two different places , one is vendors directory and other option is module directory.
I prefer to keep this module in vendors directory. So my folder structure will be webroot/vendor/StaticFileVersioning. You can download at any time sample files from the below URL.
Crate a StaticVersion.php Class .
configuring it as an invokable in module.config.phparray( 'invokables' => array( 'StaticVersion' => 'StaticFileVersioningViewHelperStaticVersion', ) ) );
Call it in the view$this->staticVersion("/public/css/bootstrap.css"); // output will be /public/css/bootstrap.css?v=d753e357740e330fae27bd2390734ffd
I hope this tutorial helps you please don’t forget to give us your feedback in comments.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.