Archive for May, 2013


CSS – Why Less is MORE

There’s absolutely NO point of me rewriting a perfectly good article thats already out there, but I will tell everyone:

STOP USING CSS!

START USING LESS!!!

It is absolutely incredible. I’m ditching all my current CSS files and refactoring them to use this stuff! There’s no turning back from this yeehah!

http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive#comment-2268

 

Here’s how to install the LESS Compiler and set up auto compiling of CSS in PHPStorm:

http://trevweb.me.uk/configuring-less-on-mac-os-x-and-phpstorm-6-0/

Doctrine 2 in a nutshell!

I found this slideshow by the legendary Ocramius (Marco Pivetta). It has all aspects of setting up and using Doctrine 2 (which is fantastic btw, I’ve been using it for a while now) and makes for a nice little introductory tutorial, or, if you are an accomplished PHP developer, a nifty little quick install and go reference!
Anyway, I quite liked it and thought if any of you haven’t tried out the power of Doctrine, go try it now! Go kid go! 😀

http://marco-pivetta.com/doctrine2-orm-tutorial/
(Use the arrow keys to change slides btw (nice little retro touch there 🙂 ))

Edit: This is old. Install Composer instead, and require the vendor/autoload.php

I’ve been messing around with CodeIgniter recently. It’s not bad at all, and for non enterprise applications or small sites, it’s a good choice! However I wanted to bring across my own classes that I’d already wrote, so what we need to do is write a helper script to set up SPL Autoloading. All my classes were written using the conventions of Zend Framework, so rather than write my own autoload feature, I thought ‘Hmm, I could also use the validators, filters, form elements, and a couple of other awesome non MVC related stuff from ZF. ‘ So here’s how:

Create a file called zend_framework_helper.php

ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.BASEPATH."../application/third_party/");
 require_once 'Zend/Loader/Autoloader.php';
 spl_autoload_register(array('Zend_Loader_Autoloader', 'autoload'));

Copy your Zend Folder to /application/third_party/ . Last thing you need to do is autoload the helper. Open config/autoload.php, find the helpers array, and add ‘zend_framework’ to it.

To get your own ZF_Style_Class to autoload, (my custom classes in this instance are namespaced DD), add the namespace to the Zend Autoloader. You can put this in its own helper or just put it after the spl_autoload_register command in the zf helper.

Zend_Loader_Autoloader::getInstance()->registerNamespace('DD_');

So now in my Codeigniter controllers, I can call my own classes, and that of Zend Framework! Remember to setView(new Zend View()) in your Form objects! Check it out:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Nofun extends MX_Controller {

 public function index()
 {
   $button = new Zend_Form_Element_Button('Frankenstein');
   $form = new Zend_Form('formname'); 
   $form->setView(new Zend_View()); 
   $form->addElement($button); 
   echo 'this rocks!<br />'.$form; 
   $test = new DD_Test(); 
   echo $test->pullLever(); 
 } 
}

Screen Shot 2013-05-23 at 21.12.50

Now we have the power of the non MVC Zend Stuff at out disposal!

If you’re interested in Codeigniter check out the awesome series of videos by David Connelly of DC Radio Network (www.dcradionetwork.com), introduction video below!

Processing CSV’s using PHP

Hi again folks!

Question – are you (like me) sick of processing CSV’s and converting them to an array? Me too!
We’ve done it umpteen times, so I thought it’s time to make a nice little static class that will  just do it for us.
So here it is!

https://github.com/delboy1978uk/del-csv

Feel free to fork it and improve! 🙂

If you have ever done any stuff with jquery/javascript that redirects you upon submitting a form, you’ll have noticed that the return key slips through the net and doesn’t obviously trigger the click event.
I’ve dealt with this nonsense plenty of times but i always end up hunting through my code to find it again. So to spare my sanity, I’m putting it here!

$('#submit').click(function(e){
 e.preventDefault();
 var name = $('#search').val();
 window.location.href = '/some/url/'+name;
 });
$("#search").keyup(function(event){
 if(event.keyCode == 13){
 $("#submit").click();
 }
 });