Tag Archives: opensource

(php) php-mvc-base project released

Whenever I create a new PHP project I use a certain base structure.
This structure allows me to have pretty URLs and have a nice way of configuring the database connections. Furthermore this structure also allows me to use a form of plugins in my system.

I have even included an example when you start your server, once the base structure is installed. Go check it out on http://github.com/jimmiw/php-mvc-base

(php) flash-message plugin

For a long time I’ve wanted a way to send messages from my controller to my view, when posting data. The message could be “Your update went well” or some error.

In the old days, I have done it like this:

controller, users/update.php:

<?php
$result = mysql_query("update users set email = '".$_POST['email']."' where id = ".$_POST['id']);

if($result) {
  header("Location: /users/index.php?message='Some long message, that might bug out'");
}
else {
  header("Location: /users/edit.php?message='ERROR because....'");
}

?>

view, users/index.php and users/edit.php:

<?php
echo $_GET['message'];
?>

However, these days are over now. With my little plugin, you can easily pass messages from the controller to the view.
All you need to do, is to include the script on your pages, then call: flash(label, message) from your controller. From your view, you can call echo getFlash(label) and that is it!

Using the same example from before, we get the following:

controller, users/update.php:

<?php
$result = mysql_query("update users set email = '".$_POST['email']."'  where id = ".$_POST['id']);

if($result) {
  // set the message
  flash('success', 'Some long message, that will NOT bug out');
  // do the redirect
  header("Location: /users/index.php");
}
else {
  // set the message
  flash('error', 'You had an error in your data.');
  // do the redirect
  header("Location: /users/edit.php");
}
?>

view, users/index.php:

<?php

echo getFlash('success');

?>

view, users/edit.php:

<?php

echo getFlash('error');

?>

Head on over to the github reposition at get it: http://github.com/jimmiw/php-flash-message

I hope you enjoy it

Snap Open forked!

I have been using Snap open in gEdit for quite some time and I love it. It’s fast and easy to use, plus it saves me from using my mouse. However, the “fast” part seems to loose it’s grounds, when you start using it in larger projects. I even started to have problems on java projects.

After some investigation, I found out that it also looked in my target folder. The .snap_open_ignore file helped a lot here though. But still the search was slow and some times the search window stalled for longer periods.

I decided to fork the current project on github and fix the problems myself. As you can see from the project data, the last commit date was around November 8th, 2008. So I assume the author sees it as complete. (meaning I will not try to submit patches to him).

Anyways, the problem with his version was, that everytime you typed, the search feature would do a file search on the disk. So, every time I typed a new letter, the plugin did a search… everytime. So.. I fixed this. Instead of doing the search every time I typed, it’s now doing it only once – The first time you open the window. This increased performance a LOT. It’s now a lot smoother to use the snap open plugin.

So head over to github.com/jimmiw, and check my version