A Little Catching up to Do

July 13th, 2009 by ScottK | No Comments | Filed in For Fun, My Life, PHPDbMigrate

So it’s been a couple of months since I posted last. I’ve really been heads down on coding at both work and home. Things are starting to lighten up in both areas and I’m ready to start a new project, PHPDbMigrate.

At work I’ve been setting up a lot of sites using CodeIgniter. It’s not a bad framework and since I’ve been away from PHP for a while it’s nice to be coding in PHP again. Not much really exciting going on at work, just setting up websites and modifications to existing code.

At home though is entirely different. For thre months now I’ve been developing Value Target. Launched it June 7. It’s definately a labor of love and still have lot’s to do on it. It’s a rails app and I’ve really fallen in love with the framework. So much so that I am going to port PyMigrate to PHP.

PHPDbMigrate is the name of the port. Yes there are “some” attempts out there to create an ActiveMigration library. I find that they are limited to MySql, not complete, or do not run code blocks. Since I’ve already accomplished that in Python, it’ll be easy for me to port to PHP. Although I won’t have the luxury of db connector library like I did with SQLAlchemy in Python.

I’ve set up the Google code project and will announce all my updates to the repository.

After I finally release a stable version of PHPDbMigrate my plan is to create a CodeIgniter library so I can develop sites even faster. So thanks for checking in and stay tunes.

Tags: , ,

Setting up Environments in CodeIgniter

May 20th, 2009 by ScottK | No Comments | Filed in CodeIgniter

I will profess that I only a month old in CodeIgniter, a framework written in PHP, I’m certainly no stranger to MVC frameworks. My work with CodeIgniter has been download the clients site, do the work and upload to clients site. Unfortunately this also means reconfiguring the app for my dev box, then hopefully remembering to change those back before I deploy.

God forbid I forget the database change configs. >.<

So with that said I’m introducing how to set up running environments with CodeIgniter so you can work in development settings and then deploy to staging, or any other you specify, without needing to change configurations. Plus you get the advantage of having the ability to modify behavior in your app based upon environment.

Note: I hacking the core of any app, but one file must be changed, but it’s the heart and soul. So in the root index.php file I’ve added: just before the final

/*
|—————————————————————
| LOAD THE FRONT CONTROLLER
|—————————————————————

raman amplifier$http_host = str_replace("www.", "", $_SERVER['HTTP_HOST']);
$environments = array("development" => "localhost",
                      "production" => "techraving.com"
                     );
$found = false;
foreach ($environments as $k=>$v) {
    if (!$found) {
        if ($http_host == $v) {
            define("MY_ENV", $k);
            $found = true;
        }
    }
}

if (!$found) {
    define("MY_ENV","development");
}

So that the heart of setting up the environment. It’s detecting the host on which you are running on and defines the MY_ENV variable for use throughout the application. It’s he only hack to the core, I promise.

The next change would be to add an entry to the CodeIgniter autoload.php. You need to add the environments.php file the autload config section… or:

$autoload['config'] = array('environments');

Now create the environments.php file in the config directory as well as an environments folder. In the environments.php add this:

<?php
include_once("environments/" .  MY_ENV . ".php");
?>

In the environments folder you need to create the different files for each environment you specify in the index.php. So in my case I have to set up a “development.php” and “production.php” file. You can certianly add different files as your $environment specifies.

So what do you do with the different environments? Well here’s what I’m doing:

environments/production.php

<?php
$config['base_url']    = "http://www.techraving.com/";
$config['log_threshold'] = 1;
error_reporting(0);
$config['cookie_domain']    = "techraving.com";
?>

and in the environments/development.php

<?php
$config['base_url']    = "http://localhost/";
$config['log_threshold'] = 4;
error_reporting(E_ALL);
$config['cookie_domain']    = "localhost";
?>

So when I’m developing locally I don’t have to change any configs when I deploy!

What else is there? Well let’s look at the database issue in the config/database.php

$active_group = MY_ENV;
$active_record = TRUE;

$db['production']['hostname'] = "localhost";
$db['production']['username'] = "";
$db['production']['password'] = "";
$db['production']['database'] = "";
$db['production']['dbdriver'] = "mysql";
$db['production']['dbprefix'] = "";
$db['production']['pconnect'] = TRUE;
$db['production']['db_debug'] = TRUE;
$db['production']['cache_on'] = FALSE;
$db['production']['cachedir'] = "";
$db['production']['char_set'] = "utf8";
$db['production']['dbcollat'] = "utf8_general_ci";

$db['development']['hostname']   = "localhost";
$db['development']['username'] = "";
$db['development']['password'] = "";
$db['development']['database'] = "";
$db['development']['dbdriver'] = "mysql";
$db['development']['dbprefix'] = "";
$db['development']['pconnect'] = TRUE;
$db['development']['db_debug'] = TRUE;
$db['development']['cache_on'] = FALSE;
$db['development']['cachedir'] = "";
$db['development']['char_set'] = "utf8";
$db['development']['dbcollat'] = "utf8_general_ci";

So as long as I’m not developing on the production site, I’m NOT working with production data!

By setting the MY_ENV varible there are so many other uses for detecting your enviroment.

Like for instance, only in production should emails be sent to the actual person, otherwise sent them to a defined email address. Yes I’ve seen it happen where developers accidentaly send email to users while developing. And boy do the users get confused; if not angry when this happens.

So by setting up enviroments we can ensure some safety as developers that we won’t be messing up production databases or causing existing users any distress. Plus as developers we don’t have to waste any time making config changes or worring about reverting them when we deploy the new code.

PyMigrate is Listed on Softpedia.com

May 20th, 2009 by ScottK | No Comments | Filed in News

I know it’s been awhile since I’ve made a post; getting ready to launch a major application as well as the paying job. ;) I have felt the blogging itch, especially since I’ve been working exclusively with the CodeIgniter framework. But today a rather exciting email came in.

I want to give a big shout out to the editors who reviewed my PyMigrate library at http://mac.softpedia.com/get/Developer-Tools/PyMigrate.shtml and included it in their Mac section listings. Other than a few comments here early on I haven’t heard anything good or bad otherwise, so this was great news to me.

Big thanks to Softpedia.com!

100% Free award granted by Softpedia