Archive for category PHP
Another gaming site goes live
Woot, I’m starting to get real comfortable building new flash gaming sites. Back before I got comfortable with PHP and Symfony it was always such a pain to launch a new site. Go buy a script costing $50-$200 dollars, tweak/build/buy a template and hack the heck out of the code to get it to work how I wanted. It always felt like such a mess, and when you finally got a site ready to go…I wouldn’t dare upgrade to a newer version of the script that ran the site.
Now, I write my own backend from the ground up. Modular classes that I can simply access or ignore anywhere I need them. If I build a new feature for one site, I can easily copy/paste or simply copy the file to the other project. OOP programming is such a time saver in many cases. The pages display exactly what I want and how I want. It’s a magical thing to get comfortable writing your own applications. I love it.
The latest site I’ve launched is another cooking game themed site, TastyCookingGames.com. This site was pretty cheap and easy to build out. Working with the platform I’ve previously built, I didn’t have much to do on the backend side of things. Simply having my designer take a character to integrate into the logo, and used another template I had designed as the base. I don’t know what it is about cooking games, but they’re hugely popular. Literally one of the biggest flash gaming niches out there. This site has minimal ads and lots of games. New game added weekly until it starts to pick up in popularity. Let’s hope this one really appeals to those girl gamers out there.
Custom default values in Symfony 1.4
Hey everyone, it’s been a while.
Lately I’ve started to dig into the php web framework Symfony. I have to say I’m very impressed. It makes building web applications fun again. Adding new features and expanding on current features become very easy.
For my day job as a system admin I’ve been deploying Symfony applications for years, but haven’t been involved with them more than. I’m very glad I finally made the plunge into Symfony myself. After a couple days of banging my head against the wall, slowly climbing the learning curve, things finally started falling in place. And since then I feel my time coding is much more efficient.
Anyways, I had some issues finding solutions to some simple problems, one of them being setting up default values.
In your config/doctrine/schema.yml file you can set models to be timestampable:
Category:
actAs: { Timestampable: ~ }
This is a nice and simply way to maintain a created_at and updated_at field. I quickly found out though, that updated_at isn’t just when you edit the file in the backend, but anytime something changes. Which makes sense, but wasn’t what I first assumed.
One of my websites tracks a lot of activity, and the updated_at was a bit heavier than I was looking for. Extra queries can quickly build up and start slowing down your website. I ended up removing the Timestampable option, and instead used a column:
column:
added: { type: date }
Now in order to automatically update the added field only when the entry is created, edit or create the following file using your model name:
lib/model/doctrine/Category.class.php
class Category extends BaseCategory
{
public function assignDefaultValues($overwrite = false)
{
parent::assignDefaultValues($overwrite);
$this->added = date('Y-m-d');
}
}
What this does is set the value of added to the current date in the 2011-04-12 format.
In the assignDefaultValues you can set any defaults you like, in the same format as the date is set.
This is very simple to setup when you know how to, but finding out how to set these defaults isn’t as easy as it could be.
I hope this simple post helps some people figure this simple solution out quicker than it took me.
Social