PHP CMS Framework
Posted by martiendejong in Martien, News, PHP, Programming on June 2, 2011
I am working on creating a PHP CMS framework for myself and others. I know that there are many CMS frameworks already, but the ones I found are very complex and/or difficult to use. In addition, I am a fan of very clean code, that’s why I like to give it a try myself.
The goal is to create something that is extremely easy to use from a programmer, designer, system administrator or end-user perspective.
It should also be as flexbile as possible and synchronize easily with other frameworks.
What I have so far is an idea about the general structure of the project. Feel free to comment criticism.
- application
- kernel
- App.php
- Module.php
- Router.php
- __autoload.php
- functions.php
- modules
- start.php
- install
- start.php
- boot
- start.php
- www
- config.php
- start.php
- public_html
- .htaccess
- start.php
$app = new App(‘path/to/application’);
App->Start();
Array to object conversion in PHP
Posted by martiendejong in PHP, Programming on June 1, 2011
I just wrote this simple function to convert arrays to objects in PHP.
For me it is convenient to have such a function at hand for quickly generating objects.
/*
* @param $class the name of the class that should be instantiated
* @param $array the array with key=>value combinations that is used to create the object
* @return an object of type $class with the values from $array
*/
function a2o( $class, $array ) { return array2object( $class, $array ); }
function array2object( $class, $array )
{
$obj = new $class( );
foreach($array as $key => $value)
$obj->$key = $value;
return $obj;
}
The question mark in URLs
Posted by martiendejong in PHP, Programming on March 21, 2010
When constructing an url via a plugin, you cannot always know at which position the ? will come.
A simple htaccess rule can be used to strip off the first ?:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)&(.*) $1?stripquestionmark=true&($2) [L,NS] [L]
Stop smoking sigarettes success
Posted by martiendejong in Drugs, Other on January 27, 2010
Well, I guess from my last assignment, I finished at least the most important part, and that is to stop smoking cigarettes 🙂
I have now found a new task for myself, and that is to do something every day that I feel uncomfortable doing.
The reason for this is that by starting to include options that I am currently uncomfortable with doing, I will increase the total number options that I have tremendously.
I started yesterday. Here are the results so far:
26-01-2010 – Go to sleep early, without the aid of cannabis
Somehow I managed to fall asleep quickly (at around 23.15) but I woke up several times during the night. I also had a lot of trouble waking up in the morning, I felt exausted. I woke up at 10.00.
27-01-2010 – Ride a bike for at least half an hour
This one went better than last one. I rode for half an hour. The cold was not so much of a problem, but the wind constantly blew my hair in my face in a way that made it impossible for me to look around. I am now back and I decided to go to a barber shop and have my hair cut. I also have muscle pain now but that is probably because I did not do much exercise for the last 5 years :p
First results:
Black lungs prevent me from smoking my third sigarette today
Posted by martiendejong in Drugs, Martien, News, Other on January 15, 2010
I am really glad to announce that I have skipped the third sigarette for today.
I hope this will help to prevent my lungs from turning into this:
My next sigarette break
Posted by martiendejong in Drugs, Martien, News, Other on January 15, 2010
When I was reviewing the introduction, I thought it was a bit short of an article for five minutes of writing.
So I started to wonder how much text I will be able to produce in those five-minute breaks.
While the fact that I do not smoke is in my opinion more important than the fact that I am writing some bullshit over here, I am pretty certain that I will not run short on text.
I now took two break within a span of an hour. Assuming I will be awake for at least 15 hours a day, I will be writing about 30 messages of 3-5 lines which makes for a grand total of about 120 lines each day.
Whoops, time’s up. Gotta go! 😀
Stop smoking & Start blogging
Posted by martiendejong in Drugs, Martien, News, Other on January 15, 2010
Hello. My name is Martien.
I am trying to stop smoking, and to start blogging.
I have now decided to try and combine these two.
Whenever I feel the need to smoke, I will instead visit this blog, and write for at least five minutes.
So… five minutes are passing pretty quickly, and they are over now.
Cya next time!
How to parse strings to numbers in T-SQL
Posted by martiendejong in Programming, SQL on December 2, 2009
CREATE FUNCTION dbo.ParseNumber ( @string VARCHAR(8000) ) RETURNS VARCHAR(8000) AS BEGIN DECLARE @IncorrectCharLoc SMALLINT SET @IncorrectCharLoc = PATINDEX('%[^0-9]%', @string) WHILE @IncorrectCharLoc > 0 BEGIN SET @string = STUFF(@string, @IncorrectCharLoc, 1, '') SET @IncorrectCharLoc = PATINDEX('%[^0-9]%', @string) END SET @string = @string RETURN @string END GO
You can now use this function in an SQL statement like this one:
SELECT dbo.ParseNumber(MyStringColumn) FROM MyTable
Or this one:
SELECT * FROM MyTable WHERE dbo.ParseNumber(MyStringColumn) > 10
More information about SQL string parsing can be found here:
Or here:
http://www.ibm.com/developerworks/data/library/techarticle/0303stolze/0303stolze1.html