PHP code example of zf3belcebur / mvc-basic-tools

1. Go to this page and download the library: Download zf3belcebur/mvc-basic-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zf3belcebur / mvc-basic-tools example snippets


/** @var \ZF3Belcebur\MvcBasicTools\Controller\Plugin\AuthenticatePlugin $authPlugin 
$authPlugin=$this->authenticatePlugin();
$authPlugin->authenticate('myCredential','myPassword'); // return \Zend\Authentication\Result
$authPlugin->logout(); // Clear session


    /** @var int defined from PHP CONSTANT "DEFAULT_LIMIT_ITEMS_PER_PAGE", if constant is not defined the value is 50 */
    protected $limitItemsPerPage;

    /** @var int defined from query param "page", by default 1*/
    protected $currentPageNumber;

    /** @var int defined from query param "limit", by default $this->limitItemsPerPage*/
    protected $itemCountPerPage;

    /**
     * @param QueryBuilder $qb
     * @param bool $fetchJoinCollection
     * @param string|null $prefix
     * @param int $queryHydrationMode
     * @return Paginator
     */
    public function createPaginator(QueryBuilder $qb, bool $fetchJoinCollection = false, string $prefix = null, int $queryHydrationMode = Query::HYDRATE_OBJECT): Paginator;

    /**
     * @param Paginator $paginator
     * @param bool $isJsonModel
     * @param array $extraParams
     * @return array
     */
    public function getPaginatorArrayResult(Paginator $paginator, bool $isJsonModel = true, array $extraParams = []): array
    

    /**
     * @param string $routeName
     * @param array $routeParams
     * @param int $statusCode
     * @return HttpResponse|null
     */
    public function checkAndRedirectUrl(string $routeName, array $routeParams = [], int $statusCode = 301): ?HttpResponse
    

    /**
     * @return MvcTranslator
     */
    public function getMvcTranslator(): MvcTranslator
    

    /**
     * @return Translator
     */
    public function getTranslator(): Translator


    /**
     * @param $message
     * @param string $textDomain
     * @param string|null $locale
     * @return string
     */
    public function translate($message, string $textDomain = 'default', string $locale = null): string


   /**
    * @return TranslatorAwareTreeRouteStack|TreeRouteStack|SimpleRouteStack|RouteStackInterface
    */
   public function getRouter(): RouteStackInterface
    

    /**
     * @return EntityManager
     */
    public function getEntityManager(): EntityManager

 
use ZF3Belcebur\MvcBasicTools\View\Helper\BTools;
/** @var BTools $bTools */
$bTools=$this->bTools();

BTools::nl2br("\n");
BTools::br2nl('<br><br>');
BTools::trim('    ');
BTools::randomPassword(10);
BTools::convertToUTF8('hello');
BTools::splitTextByDotOrSpace('cut this',false,3); // cut...
BTools::slugify('حولا كيو تل'); // 'hwla-kyw-tl'
BTools::slugify('你好,这样的'); // 'ni-hao-zhe-yang-de'
BTools::slugify('그러한 안녕하세요'); // 'geuleohan-annyeonghaseyo'
BTools::slugify('त्यस्तो नमस्'); // 'tyasto-namas'
BTools::slugify('hola que tal'); // 'hola-que-tal'
BTools::slugify('привет, что такой'); // 'privet-cto-takoj'

$bTools->getParams(); // return Params Plugin Controller 
$bTools->getPluginManager(); 
$bTools->getMetaBy('name','description'); // get meta name=description content 
$bTools->getMetaBy('property','og:locale'); // get meta property=og:locale content 
$bTools->getMetaByName('description','things'); // get meta name=description content, if not exist return 'things" 
$bTools->getMetaByProperty('og:locale'); // get meta property=og:locale content
$bTools->getRouteMatch();
$bTools->getRouter();
$bTools->getFormElementManager();
$bTools->getMvcTranslator();
 
// Only in view
$bTools->getParams()->fromRoute(); // return array params from route
//Layout Or View
$bTools->getParamsFromRoute(); // return array params from route
$bTools->getParamFromRoute('param','default'); // return param from route or default value
$bTools->getParams()->fromRoute(); // return array params from route