Checkdomain.de is giving away free domain maps

While searching for free domains for a new university project on my favourite domain registration site checkdomain.de I noticed a cool offer they are having at the moment: Get a free world map of all top level domains in the world.

All you have to do is go to their website and read the instructions: blog about the offer, tell them, get the free map…

Posted in General | Leave a comment

.net web development magazine

While I was dwadling away my time on Manchester airport waiting for my return flight to Munich about a month ago I checked out a couple of shops which mainly sold books, magazines and newspapers. I was more than surprised how many readings they had about specific topics like web-development or -design.

After a quick look through some of them I bought a magazine called .net – develop, discover, design – also labelling itself as “the world’s best-selling mag for web designers” – doesn’t that sound promising? ;)

In the airplane I had a more detailled look and found some interesting articles. The main topic about using CSS frameworks sounded like a good approach to me and I decided I will give it a try at some point.

At home I thought of getting an subscription of the magazine but so far I havn’t ordered anything. In my eyes the problem of magazines in general is that usually many articles are not very useful nor interesting. To use the .net magazine as an example – after reading about 40 interesting pages there are still 90 pages which I paid for left – they will probably stay unread until I bin the magazine. The fact that the subscription is 90 Euros per year for people who live in the EU makes the mentioned problem even worse.

I may buy another magazine in a shop but in my opinion it is better to have some good blogs in a nice feedreader to find interesting headlines articles quickly by just looking through the headline-list. Let me know what you think about (web-development) magazines and your way to keep up-to-date.

Posted in General | Leave a comment

Social Media?

Just some eye-candy before I am off to Ibiza tomorrow: Watch and enjoy!

candyman
Posted in General | Leave a comment

Move rows from one table to another in MySQL

A few days ago one of my databases had massive performace problems due to a table which got really big. Instead of optimising all queries I thought of other ways to speed it up again. As this table contains many records which won’t ever be used again, I created a new table called mytable_archive and tried to move old data from mytable to mytable_archive.

After I spent a while with googling for solutions I found an easy way to move data from one table to another, presumed that the tables have the same structure.

INSERT INTO mytable_destination (col1, col2, col3) SELECT * FROM mytable_source WHERE created < NOW() – INTERVAL 6 MONTH;
DELETE FROM mytable_source WHERE created < NOW() – INTERVAL 6 MONTH;

MySQL will execute the SELECT-Part and will use it for the INSERT-part which inserts the selected records from mytable_source into mytable_destination. After copying the desired rows you have to delete them from the source table to complete the “moving process”.

Replace mytable_destination with mytable_archive or however you called your archive-table.

I hope these statements are useful for some of you, please let me know.

candyman

Posted in MySQL | Leave a comment

CakePHP status image helper

Usually most of my tables contain a column named status to classify the record as “active”, “inactive” or “spam”, just to mention a few possibilities.
In the admin panels of my applications I use images to represent the status. By the time i got irritated with putting a few lines of code, which determines which image to display, to every table with a status-column so I decided to code my first helper quickly.

It uses CakePHP’s html helper to generate the image-code and works for boolean values (1, 0) as well as for “active”, “inactive”, “pending”, “spam” and “deleted”.
If these values are not enough it is easily extendable for other requirements.

<?php

class StatusHelper extends AppHelper {
var $helpers = array(‘Html’);

function display($status) {
$img = array();
switch($status) {
case ‘active’:
case 1:
$img['url'] = ‘ok.png’;
$img['alt'] = ‘Active’;
break;

case ‘inactive’:
case 0:
$img['url'] = ‘error.png’;
$img['alt'] = ‘Inactive’;
break;

case ‘pending’:
$img['url'] = ‘pending.png’;
$img['alt'] = ‘Pending’;
break;

case ‘spam’:
$img['url'] = ‘spam.png’;
$img['alt'] = ‘Spam’;
break;

case ‘deleted’:
$img['url'] = ‘delete.png’;
$img['alt'] = ‘Deleted’;
break;
}

return $this->Html->image(
‘/img/icons/small/’ . $img['url'],
array(‘alt’ => $img['alt'], ‘title’ => $img['alt'])
);
}
}

?>

It is very easy to use (don’t forget to add “Status” to your controller’s helper-array):

<?php echo $status->display($user['User']['status']);  ?>

I use icons from the free HumanO2 Iconset by schollidesign:

Let me know if you have any suggestions.

candyman

Posted in CakePHP | Leave a comment

Translating CakePHP’s validation error-messages

Recently I faced the problem of translating a website into different languages. It works like a charm using CakePHP’s __() function though it does not work offhand for validation messages in the model because you can’t call a function outside a method in a class (the modelclass in this case):

<?php
class MyModel extends AppModel {
var $name = ‘MyModel’;

// This won’t work!
var $validate = array(
‘username’ => array(‘rule’ => ‘notempty’, ‘message’ => __(‘error1′, true))
);

?>

After some investigation I found out that setting the validation variable in the Models constructor should help. Indeed, it did work – but the problem is that the Models are interpreted quite early – before the AppControllers beforeFilter is executed at least. So, for example, if you set the language to a user-defined value in beforeFilter, the validation messges will still remain in the standard language (determined by i18n I think). I looked up the models callback possibilities and found what I was looking for: beforeValidate.

Defining the validation variable in the beforeValidate method also solves the above mentioned problem:

<?php
class YourModel extends AppModel {
var $name = ‘YourModel’;

function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);

$this->validate = array(
‘email’ => array(
‘unique’ => array(
‘rule’ => ‘isUnique’,
‘message’ => __(‘Another user is using this e-mail address.’, true)
)
)
);
}
?>

Using this piece of code allows you to set the language to a pre- or user-defined value combined with translated error-messages for Cake’s built-in data validation.

Please let me know if you have better ways (I guess there are, maybe in CakePHP 1.3) to solve it or in case you find my solution helpful.

Posted in CakePHP | Leave a comment

First Post

Hello,

this is my first post in my new blog I just set up before. As almost every web developer I wanted to share my experiences and creations with others too. I don’t know how often I’ll find time to post something but I’d want to do it on a regular basis.

Whilst waiting for the first post you can explore the pages About me and My work, which are already filled with content.

candyman

Posted in General | Leave a comment