Top 6 PHP Techniques That Will Save You Time, How to do, Top 1o Lists, Hacking, Games, Pictures, Tips and Tricks, PHP, Movies.

Top 6 PHP Techniques That Will Save You Time

1.
Properly Create a Website Index Page


Creating your web site index page is definitely the initial thing to do for all website which you create.

2.
Use the Request Global Array to Get Data

There is really no reason to apply $_GET and $_POST arrays to get values. $_REQUEST, is one more global array that fetches you possibly a get or form request. Therefore, it’s most times more convenient to use something like this to parse data :
$result = $_REQUEST['Name'];

3.
When You Need Just an Object, Use a Singleton Pattern

It happens pretty often in PHP that we just require a one object created a single time and then used globally throughout our whole program. A excellent example of this is the smarty variable that has to be initialized once and then is used all over the code. A smart way to do that is a Singleton pattern, where an object is just created once and for all. The way to do this is like :
function MysmartyObject()
{
if ($GLOBALS['config']['SmartyObj'] == 0)
{
$smarty = new SmartyGame();
$GLOBALS['config']['SmartyObj'] = $smarty;
}
else
$smarty = $GLOBALS['config']['SmartyObj'];
return $smarty;
}

Observe that we have a global smarty variable (initialized in config.php in example) and if it equals 0, we go about developing a new smarty object. If not, it means that the object is already created and we just need to return it.

4.
A php File Handles Input, a class.php File Handles Functionality

It’s pretty essential that you learn don’t mess the code that retrieves user input and redirects it to any functions, with those actual functions. The concept is really quite simple. The php file gets any input that we need and then redirects execution to a function residing to the class file. For example, let’s guess that a url is like “index.php?page=profile&action=display”. The profile.php file retrieves the url and gets that action is “display”. Then, by using a simple switch, we execute the actual display function like :
require_once PROJECTROOT.'libs/messages.class.php';

$message = new Message();

switch ($action)
{
case 'display':
$message->display();
break;

...

5.
When You Absolutely Need Global Values, Create a Config File

It’s a bad practice to create global values for everything. There are actually limited cases when you’d probably really need to do so. Doing it for database tables or database connection information is a good idea, but do not use global variables throughout your PHP code. Moreover, it is always a better idea to keep your global variables at a single config.php file.

Hey Wait, Have you notice here is Actually 5 Tips i have been shared. Suggest me a 6th Tip for Insert here :)

Related posts:

Tags: , ,
© 2012 Ataaso. All rights reserved.
Read » Top 6 PHP Techniques That Will Save You Time Article, Top Ten List, Wordpress Hack, Programming Tricks, Amazing Pictures