Keeping your core.php DRY

5 Nov 2008 In: CakePHP

Something that I have been taking advantage of in my Cake 1.2 apps for quite a while now, is the ability to separate your custom config options from your app’s core.php file. And I am pretty sure that it is one of those lesser know features in 1.2.

The core.php file within your app’s config directory is used to store application wide configuration variables. Things like your debug level, cache settings and sessions store are set here using Cake’s very useful Configure class. This file can start to get quite large and unruly as the development of your app progresses. So one of the first things I do when I start a new app, is to separate my custom application config variable into another file within the config directory. This then keeps the core Cake configure settings separate from your custom ones, and keeps things a little dry.

Just create a new file in your app/config directory. You can name this anything you want, but I usually go with something like ‘config.php’ or ‘app.php’. As long as it ends with ‘.php’, it doesn’t matter.

Then in your app/config/core.php file, add the following line to the top of the file:

Configure::load('config');

As long as you pass the name of your newly created file, then it will be fine. So the above will work if I created a file called app/config/config.php.

Then within your new config file, you can set any config variables you wish. However, you don’t use the familar Configure::write('name', 'value'); convention. The variables that you set within your custom config file should be specified using arrays. Like this:

$config['name'] = ‘value’;

All variables in this file only, should set within the $config array as array name/value pairs. If your custom config file is called ‘app.php’, then the array name would be $app. So effectively, you could create as many of these custom config files as you wish. Perhaps if you had distinct sections of the app. I usually just create one, so I can easily access my custom config vars, without worrying about Cake’s built in config vars.

You access these custom config variables in the exact same way as you would any of the other built in core config vars.

Configure::read('name');

Enjoy!

DB Migrations moves home

2 Nov 2008 In: DB Migrations

I’ve been slowly moving all my public and private projects over to Git and Github whenever, and whereever I can. I’ve already created a mirror of the CakePHP 1.2 branch at Github, and I have a number of my private projects up too.

So I just completed the switch for CakePHP DB Migrations. The source is now available on Github and is open to any pull requests. If you have any funky new features, or really need a bug fixed quickly, please feel free to fork the project. But please remember to send me a pull request.

I also moved the Google Code wiki into Github, and enhanced it a little. The wiki now includes some YAML migration examples, and will be expanded with more info and tutorials as and when I can.

The final step of the move, are the tickets/issues. And because it works so nicely with Github, I decided upon using Lighthouse. So any bug reports, and/or feature requests should now be sent to Lighthouse.

Thanks again for all the support. My hope in moving to Github, is that I can enhance the community aspect of this project, and to encourage more involvement from those of you who use it. I’m all ears!

Not posted much here recently, so It’s great that all of a sudden I have lots of Cake related news and tidbits to share with you all. So hopefully, this will be post number one in a long series of posts covering CakPHP related news and items, entitled Cake Nibbles. Enjoy!

PHPShop

The Google Group revealed some interesting news about a well know open source PHP shopping cart application. It appears that the next version of PHPShop will be built with CakePHP 1.2. That can be nothing but positive for Cake Land.

Google No. 1

Search for “PHP framework” on Google, and guess what? Cake is now number one! Oh yes, NUMBER 1! Top of the pops!

Debug Kit

Not content with being one of the biggest contributors to the core, Mark Story has created a plugin for CakePHP to help with debugging your applications. The Cake DebugKit, which is now publicly available at GitHub, is similar to the extremely helpful Debug Bar that can be found in the Symfony framework. It displays at the top right of your screen, and shows you info about your app, such as load time and SQL queries.

It’s early days, but its a great start, and is something that is sorely needed in Cake. I hope to help out with it myself. And the idea of including it in a plugin is genius, and has made me realise how powerful the plugin architecture has become in 1.2

TextMate Bundle

Also on GitHub, you can now find another version of the Cake TextMate bundle. But this one is somewhat official, in that it is being maintained by Nate; Cake’s Lead Dev.

So thats it for this issue of Cake Nibbles, but I hope to post again soon.

If you have any interesting, or non-interesting news in Cake land, please let me know.

After months and months of delays due to work constraints, and other crap, I decided that I needed to get my head down and release v4.0 of CakePHP DB Migrations. So that is exactly what I just did!

v4.0 is now available in all its glory at the Google Code repo at http://code.google.com/p/cakephp-migrations so get it while it is hot.

You can download it here.

I plan on creating a new screencast soon(ish), that will include all the updated features and shortcuts, and will also be easier to hear me and will hopefully be a little shorter and concise. But until then, please play around and let me know if you have any questions at all.

Here’s the changes taken directly from the changelog:


[*] errr… lots of fixes
[*] Fixed bug with old style version numbers
[*] Fixed bug where fkeys were trying to be created with auto_increment
[+] Can now specify whether to use Cake’s UUID for the ID column within migration files. Example: “id: uuid”
[+] Can now pass “id: false” within migration file, and no ID column will be created.
[-] Deprecated “no_id: true” in favour of “id: false”
[*] ID column is now correctly set as Primary Key when using UUID type.
[+] Added support for MySQL specific table options (comments, engine/type, collate and charset)
[+] Version numbers now use timestamps so as to minimize conflicts
[+] Now supports interleaved migrations;
when migrating up, will run migrations that have not yet been run, and will ignore any non-run migrations when running down.
[+] Added info option (cake migrate info), which shows information on migrations
[+] Can now specify version number when running up/down, thus allowing you to only run the up/down block of a specific migration
[+] Schema table name is now customizable
[+] Now supports PHP arrays in migration files

I hope to write more about these when I don’t have so much decorating on the house to do.

CakePHP 1.2 RC3 is Released

2 Oct 2008 In: CakePHP

Just woke up to find I missed two exciting events in CakePHP land. First and most important is the release of Release Candidate 3 for 1.2. This release cannot be understated, although I think considering the amount of work that has been done on this release, we should be seeing a stable release of 1.2. I know it was only released a few hours ago, but right now there are a grand total of ONE bug. And that one bug will be fixed in 3 second, when I commit the fix ;). Go over to the Bakery and read the announcement from Nate, and you will understand the amount of work that has been done.

Although I have been a small part of this, and helped by committing some fixes and enhancements, constraints on my time and family life have kept a some what tight lid on my commitment to contributing. But I hope to change that once 1.2 goes stable. As some of you know, I already have some cool new features waiting in my unofficial CakePHP Github repo. So hopefully these will appear in the core of 1.3, or maybe even 2.0!

Oh and by the way, a little bird tells me that Cake will be ditching SVN after 1.2 is released, and will be embracing Git and Github in all its glory. Watch this space!

Second exciting piece of news was the release of a new episode of The Show. It’s been a long period of quiet since the last show aired, so this episode is well worth the wait. Well, I am assuming it is, as we only got a one hour heads up from Nate, on Twitter. And that was when I was fast asleep. So I will will have to wait for the episode to be put online.

So congrats to all. I would also have to agree with Nate, on naming Mark Story, the man who has contributed the most to this release than any other person. So everyone please enjoy Mark Story Day!

Who is Developing with Style?

My name is Joel Moss, a web developer and all round nice guy, living in Manchester, England. I am currently working full time for ShermansTravel.com, but I fill whatever spare time I have with lots of good and wholesome "stuff"! Like developing my own ideas; such as Tooum, contributing to the excellent CakePHP framework, and doing more work for ShermansTravel.

So this is my blog - my soap box! Here I attempt to share my likes, my dislikes, and my opinions. As well as providing some occasional respite from the daily crap we all endure. Enjoy ;)

Hey, if you want to reach me, i'm available via email:joel[at]developwithstyle[dot]com, and AIM:joelkmoss.


Categories

Archives