corner6labs

Just another WordPress.com weblog

How to prevent child view modules from executing outside a parent view

Long before the days of everyone preaching MVC…MVC, and before I became obsessed with the Zend Framework I use to actually implement a form of MVC in my PHP applications. PHP programmers use to refer to it as templating. One thing that always came up while templating was how to prevent child view templates modules (such as forms) from executing outside of parent views. One technique I employed was to use the PHP define() method to “define” a “passport” CONSTANT variable in my main view file or in the global config file. I would then use the defined() method in child view modules to check if the passport variable existed. here is an example:

define("APPLICATION_NAME","v1.0");

If you have defined your config settings withing a class, you can use the “const” keyword

Then you can check for the constant in your child view files like this:

if(!defined("APPLICATION_NAME")){ exit("invalid view setup"); }

Its is a very simple test but it has proved to be effective time and time again.

Advertisements

Filed under: PHP, Tips & Tricks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

August 2009
M T W T F S S
    Sep »
 12
3456789
10111213141516
17181920212223
24252627282930
31  
%d bloggers like this: