Well I've been coding in PHP happily for around a year now and even though sometimes there's no mood for coding the fix for me seems to be using PHP frameworks - and now I can't stop coding!!
There is one specific PHP framework - open source and all, that's called
CodeIgniter, its a really easy PHP framework and it literally comes out of the box. I was setup and already making stuff in 10 minutes, and now I have created a small application (probably the smallest I've done) which sends mail via a form. I probably guess that other frameworks are the same, well this has libraries for absolutely everything, including sending e-mails (and attachments), to creating HTML forms. I've never really known what a PHP framework does before but this seriously has blown me away - and I'll be rewriting my forum script
from scratch using this framework.
The user guides are probably the best I've ever seen and I probably would of lost even the first insight without them, including two fantatic tutorials on their site too, which helped kick me off the ground.
They use the MVC approach and it is really easy to understand.
V: stands for views and its the pages that the content is viewed from, from Controllers.
C: controllers control the functionality of your application, different functions are for different segment URLs (so function hello() would be for yoursite.com/hello) for instance. Here is my small app:
PHP Code:
<?php
class Site extends Controller {
public function index() {
$this->load->view('site_view'); // we allow this function to be used in site_view.php
$this->load->helper('form'); // start the forms helper
echo "Send Mail:";
echo form_open('site/send');
echo form_input('message');
echo '
';
echo form_submit('submit','Submit Message');
echo form_close();
}
public function send() {
$this->load->view('site_view'); // we allow this function to be used in site_view.php
$this->load->library('email'); // start the email library
$message=$_POST['message'];
$this->email->from('ben@dynbb.com','Ben Stones');
$this->email->to('stonesben@gmail.com');
$this->email->subject('Some subject');
$this->email->message($message);
$send=$this->email->send();
echo $this->email->print_debugger();
if($send) {
echo "Sent";
}
else {
echo 1;
}
}
}
?>
it isn't as complicated as it seems. If you know OOP and are advanced to intermediate in PHP, I recommend
seeing this first - and you'll seriously change your mind.
*breathes*
