Restricting Access to All Pages Using Zend 2 and ZfcUser

A new application that I’m working on needs to block all access to every page, except the login page, for unauthenticated users. After setting up Zend 2 with the ZfcUser module, this is a piece of cake. Just update your module/Application/Module.php file with the following code:

$moduleRouteListener = new ModuleRouteListener();

$e->getApplication()->getEventManager()->getSharedManager()->attach('ZendMvcControllerAbstractActionController', 'dispatch', function($e) {

$controller = $e->getTarget();
$sm = $e->getApplication()->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');

if (!$auth->hasIdentity()) {

// If on login / registration page, let them pass
!($e->getRouteMatch()->getParam('controller', 'index') == 'zfcuser' && $e->getRouteMatch()->getParam('action', 'index') == 'login')
&& !($e->getRouteMatch()->getParam('controller', 'index') == 'zfcuser' && $e->getRouteMatch()->getParam('action', 'index') == 'register'))
}, 100);


Wala. All requests, that are not to the login or register pages, are now forwarded to http://yoursite/user/login if a user is not authenticated.

Creating Entities from Existing Database with Doctrine 2 and Zend 2

So I’m upgrading an existing system to use Doctrine, Zend 2 and Dojo and the first step was to setup Doctrine with the existing database. I really didn’t want to have to manually code up all of the Entities so I was looking to see how I could use Doctrines tools to automate this. Here’s how:

(note, I’m using Windows)
1) Create a “tmp” directory in the root of your site

2) From the root of your Zend 2 site, run

php vendordoctrinedoctrine-modulebindoctrine-module orm:convert-mapping —–from-database xml .tmp

3) Once the .dcm.xml files have been generated, you need to tell Doctrine to use the XML driver by updating the vendordoctrinedoctrine-modulebindoctrine-module.php file:

// Add the following three statements above the last two lines
$driverImpl = new DoctrineORMMappingDriverXmlDriver(
/* @var $em DoctrineORMEntityManager */
$em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
// end of new code

/* @var $cli SymfonyComponentConsoleApplication */
$cli = $application->getServiceManager()->get('doctrine.cli');

4) Create the php entity files:

php vendordoctrinedoctrine-modulebindoctrine-modules orm:generate-entities ----generate-annotations="true"

Drupal 6 Custom Module Causes WSOD

You created a custom module and tried to setup a theme function with it. After changing an Administration setting, you get the WSOD (white screen of death) on all pages. There are no errors in the Apache or PHP error logs. This is not a memory or time out issue. You screwed up in your module 😉


# Disable your module
update yourdrupaldatabase.system set status = 0 where filename like 'sites/all/module%' and name like 'your_custom_module_groups_%';

# Remove main cache
delete from yourdrupaldatabase.cache;

# Remove all other cache tables.
delete from yourdrupaldatabase.cache_*

Now you should be able to access the site. After you remove any template references in your module code and delete any .tpl files, you can safely re enable your custom module:

update yourdrupaldatabase.system set status = 1 where filename like 'sites/all/module%' and name like 'your_custom_module_groups_%';

Cheers, strick.

Create a Title / Subtitle Pair in from a Controllers Name</a></h2> </header><!-- .entry-header --> <div class="entry-content"> <p>If I have a website called Blog with two main sub pages; about me and bio, I like to have the HTML title to always be My Site: Current page. Since all of my controllers have descriptive names, I can just put the following in my layout:</p> <p><code lang="php"><br /> <title>Blog: <?php echo ucwords(str_replace("-", " ", Zend_Controller_Front::getInstance()->getRequest()->getControllerName()));?>

This would give me the following when users navigate to my site:

Blog (
Blog: About Me (
Blog: Bio (