Undefined index: role_id at BjyAuthorize

Standard

Strange error around here:

 PHP Notice:  Undefined index: role_id in /var/www/site/vendor/bjyoungblood/bjy-authorize/src/BjyAuthorize/Provider/Role/ZendDb.php on line 90

 

It seems that SQL script creates user_role table with userId field but, at php module is requested role_id… just change column name and it’s fine!

Hope it helps!

Zend Framework 2: Use Different Layout Templates for each module

Standard

Hi there! Having different modules (like: default application module and CustomModule1) I had trouble setting different html layouts to them!

The solution is edit your module’s bootstrap like this:

public function onBootstrap(MvcEvent $e)
{
// You may not need to do this if you’re doing it elsewhere in your
// application
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);

$sharedEventManager = $eventManager->getSharedManager(); // The shared event manager
$sharedEventManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function ($e) {
$controller = $e->getTarget(); // The controller which is dispatched
$controllerName = $controller->getEvent()
->getRouteMatch()->getParam(‘controller’);
if (!in_array($controllerName,
array(‘administration’))
) {
$controller->layout(‘layout/layoutname’);
}
});
}

please do not forget to include the template at templates path at module.config.php

‘view_manager’ => array(
‘template_map’=> array(
‘layout/layoutadm’ => __DIR__ . ‘/../view/layout/layoutadm.phtml’,
),

Hope it helps!

Quick Tips: Doctrine 2 useful commands

Standard

Hi there! Using Zend Framework 2 With doctrine have been nice! But commands for update and validate schema are hard to keep it in mind! So on Root Dir:

Validate Schema: 

./vendor/bin/doctrine-module orm:validate-schema

Create Schema:

./vendor/bin/doctrine-module orm:schema-tool:create

Validate an Update:

./vendor/bin/doctrine-module orm:schema-tool:update –dump-sql

Apply an Update:

./vendor/bin/doctrine-module orm:schema-tool:update –force

Hope It helps some one!

Don’t forget to leave a comment!

MySQL select to file

Standard

So, the idea is to execute a query in MySQL but export the result to a CSV file.
MySQL gives you the statement INTO OUTFILE
Example:

Select * from table_name into outfile ‘/path/to/file.csv

Hope it helps.