Archive for the ‘php5’ Category

Quickly turn on error reporting to see errors.

July 13th, 2011 1 comment

I frequently run into a page where php isn’t displaying errors… A quick way to turn them on without changing the php.ini file is:

error_reporting(E_ALL & ~E_DEPRECATED);

ini_set('display_errors', 'on');

Note: This will not show compile / fatal errors, as the page won’t even run, but if it’s just a regular non syntax related error, it will not be displayed.

Update Thanks for the way to remove deprecated warnings Jacob.

Categories: php5 Tags:

Generating Documentation from XML using xslt

July 10th, 2011 No comments

When I worked at Infusionsoft I re-cycled some code I used to generate a php sdk into code that would generate documentation for the API, it wasn’t pretty but since I didn’t get official time to do it that’s what happens. I left the company, but fortunately Vivin Paliath is actively maintaining the auto-generation of the documentation using xslt, see: Now, if he gets it Mavenized, and part of the formal build process than it will be the icing on the cake for all of us Infusionsoft API developers.

Categories: php5 Tags:

Baking Cake Controllers and Views

July 5th, 2011 No comments

Scaffold is awesome!  It genereates everything you need for CRUD, and is fully customizeable…

To use it do…

cake bake controller {controllername} scaffold   (NOT scaffolding)

To make the views

cake bake view {controllername}

Viola!  Instant coolness.

Categories: php5 Tags:

Never ever ever make a php config file not a php file…

November 8th, 2010 1 comment

I was using a php sdk today where the config file is NOT a php file, but rather a file named .cfg…

The problem?  You have to restrict access to this file with a .htaccess file to prevent someone from reading it.  Whereas, if it were a php file, not only would you not have to prevent access to it, you also don’t have to write your own parser.

Lesson…  Don’t use a cfg file, where a php config file will do.

Categories: http, php, php5, web Tags:

Uniserver – Things I Learned Today

October 26th, 2010 No comments

Uniserver on Windows REQUIRES the .htaccess file to have the “Options +ExecCGI +FollowSymLinks” line in it… Or else you get a 403 forbidden on every page you try to access.

Categories: apache, php5, web Tags:

Awesome Prototyping Tool!

October 25th, 2010 No comments

Check out this AWESOME free prototyping tool. Pencil Project.  (It’s a Firefox Plugin / XUL Application)

It let’s you mock up fully functional websites without writing any html code.  Then, you can export it as html, and use it as a starting point for a better mockup.  Or export all the pages to png’s in one shot, and use those as a starting point in Adobe Illustrator, or your design tool of choice.

It’s great for useability testing.  Mockup your ideas.  Put them in front of customers / users, re-prototype, and continue until you get it as good as possible, and meeting your cash cow customers’ needs.  THEN make it look good.

Things I Learned Today

July 22nd, 2010 No comments

Uniserver on Windows REQUIRES the .htaccess file to have the “Options +ExecCGI +FollowSymLinks” line in it… Or else you get a 403 forbidden on every page you try to access.

Categories: php5, web Tags:


April 27th, 2010 No comments

I’ve used phpMyAdmin for a while, but I find it to be a little heavyweight at times. Sometimes I just want to run a simple query. The MySQL client is obtuse to use sometimes. So I went on a search for alternatives.

I now use phpMiniAdmin almost exclusively. It’s extremely light weight, fast and has LOTS of neat features. It provides everything I need 99.9% of the time. And it’s easier to configure then phpMyAdmin.

Categories: mysql, php5, web Tags:

Magento – WOW!

January 19th, 2010 No comments

Some say that Magento is horrible to work with. I say they are wrong. Magento is one of the most well designed pieces of software I’ve ever seen. Complete inversion of control. Awesome extendability. Sweet seperation of concerns. Proper use of classes, it’s all there.

But… It’s under documented, and it has a few core concepts you have to understand before it makes sense.

Recently I need to make a new shipping method for Fortunatly for me, magentomagick had a great article that had instructions start to finish (except for two details that are mentioned in the comments) for just such a task.

Categories: php5 Tags:

So you want PHP Templates, eh?

September 2nd, 2009 No comments

PHP Templates! Everyone wants them, some people try to provide them to others, but deep down inside, you all know smarty isn’t the way to go… Allow me to show you a better way.

Just use PHP! Yes, that’s right! PHP is almost designed from the ground up natively support templates!

Here’s the secret… When you include a php file (using the include(“somefile.php”) method, the php code inside the included file has the same variable scope as the code block that included it… So… Take the following two files….

  function go(){
    $a = "Hi There!";
<?php echo $a; ?>

The output would be:

Hi There!

If you’re a noob, another name for this (if you make extra effort to not put anything but loops, and echos in your template) is MVC (Model View Controller). While it isn’t a complete implementation, it’s a really really good start and makes writing and maintaining a site WAY easier. Cake PHP uses this approach for it’s views (aka templates) as well. Java uses this, but instead of the “view” using the local variables where a page is displayed, the data you want the view (or jsp page in java) to have access to are put in the request object as an “attribute”.

I, personally, put the variables I want to use in a “template” (aka “view”) in a global array ($GLOBALS[‘params’][‘name’] = “bob”;) It isn’t the best practice, because some part of your code far away could write to this and mess something up, but for simple sites, I find it quick and easy.

Of course, if you REALLY want a templating system, you could use SMARTY. (Blech!) But, I really recommend you just get used the to the echo statements and use php to render templates.

So, some sample code from a site of mine is:

require_once(BASE_FS_PATH . '/classes/BookService.php');
	case 'Research':
		$book = BookService::importBook($_POST['ean']);
		$_GLOBALS['params']['book'] = $book;
		include(BASE_FS_PATH . '/views/pages/research.php');	
	case 'mark_not_sellable':
		$book = BookService::importBook($_GET['ean']);
		$book->sellable = 'no';
		$_GLOBALS['params']['msg'] = 'Book Marked As Not Sellable.';
	case 'mark_not_available':
		$book = BookService::importBook($_GET['ean']);
		$book->available = 'no';
		$_GLOBALS['params']['msg'] = 'Book Marked As Not Available.';
	case 'details':
		$book = BookService::importBook($_GET['ean']);
		include(BASE_FS_PATH . '/views/pages/research.php');
function show_details($book){
	$_GLOBALS['params']['book'] = $book;
	include(BASE_FS_PATH . '/views/pages/details.php');

And the “view” for this code (details.php) is:

<body style="width:950px; margin: 0 auto; text-align: left;" class=" yui-skin-sam">
			include(BASE_FS_PATH . '/views/pieces/menu_and_js.php');
		<div style="text-align: center;">
			<?php echo $_GLOBALS['params']['msg']; ?>
			<h1><?php echo $_GLOBALS['params']['book']->title; ?></h2>
			<li>Ean: <?php echo $_GLOBALS['params']['book']->ean; ?></li>
			<li>Available: <?php echo $_GLOBALS['params']['book']->available; ?></li>
			<li>Imported: <?php echo $_GLOBALS['params']['book']->import_date; ?></li>
			<li>Cost: <?php echo $_GLOBALS['params']['book']->cost; ?></li>
			<li>Change In Inventory: <?php echo $_GLOBALS['params']['book']->change_in_inventory; ?></li>
                         (More Code That's been removed for this example)

Anyways, there are LOTs of templating engines out there you can use instead, but I would discourage it. This is the fastest, simplest, most powerful way to do templates (IMO).

Categories: 100 Weeks of PHP, hacks, php5 Tags: