I am interested in building my own php framework for my personal use to make my coding life easier. I am doing this as I am fairly (sort of) use to php now, and can’t seem to get use to any framework.
I have an idea of making loads of functions in a .php file. Like I have started to do, sor for the send mail function I have simplified it (for my use):
function sendmail($to, $message, $subject, $from){//USE sendmail($to, $message, $subject, $from)
$headers = "From:";
$headers .= $from;
$headers .= "\r\n";
$headers .= "Reply-To:";
$headers .= $from;
$headers .= "\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
}
This will then be used in a contact form:
sendmail($_POST['to'], $_POST['message'], $_POST['subject'], $_POST['from']);
This mail function works for me.
However, I am not sure at all if this is correct to make a framework like this. I have looked into classes and objects for php but cant seem to understand them as there is no understandable/easy tutorial.
People are going to tell you to not write your own framework, to use an existing one. Do not listen to them. It is a good learning experience and will help you understand the concepts which will make other frameworks make a lot more sense to you.
I personally needed to understand 2 things better before being able to use other peoples frameworks (and obviously write my own):
I spent days reading every OOP tutorial on PHP and every tutorial/wiki page on MVC. Then as a learning experience i wrote my own framework. Then i learned from my mistakes and I started from scratch and wrote another framework. I probably wrote 5 versions. Then i decided to try out code igniter. After all the reading and practicing i finally understood it.
Since then i have only been using other peoples frameworks.