Learn DooPHP: High performance PHP framework

Using DooTranslator for translation

DooTranslator finnaly came out, it supports “Csv“, “Gettext“, “Array“, “Ini” for now, soon it will be implemented other “file types”. So for example you have your translation file with this contents:

en.svn

test;"This is just a test!"

Lets initialize DooTranslator class:

$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/en.csv');
 echo $translator->translate("test");

As you can see its very simple, first argument is file type for translation and second is path to the file, third argument can be options array. For Csv you can set options like: delimiter, enclosure and length. Default value for delimiter is “;” and for enclosure is “.

Now we will add some options to our call, lets say we want some other delimiter then “;” and we want to add some caching.

$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/main.csv', array('cache' => 'apc', 'delimiter' => '|'));

So now we have added cache mechanism that is “apc” and we added delimiter that is “|”, now in our en.csv we must change delimiter:

test|"This is just a test!"

Supported cache mechanisms are “apc”, “php”, “xcache” and “eaccelerator”.

Now lets add placeholders for translate method:

$translator->translate("Hello [_1], wellcome to my website!", array("John"));

This will show translated string with: “Hello John, wellcome to my website!”.

Ok thats about it, if you have any questions please do ask, this is simple translation class its still

Read More...

Managing your database(s) with DooPHP

This tutorial will demonstrate how to use the DooManageDb and DooUpdateDb classes to manage your projects database.

These classes have been developed to allow your application(s) to be independent of the database your users choose to use by allowing standard database definition to be used to define your database which is then translated into the SQL needed for the database engine the user is using. It also supports easy upgrading (and downgrading) of the database to allow for better version control support and rolling out of updates and unit testing.

In order to follow this tutorial you will need to use the latest version of DooPHP avaliable form the SVN repository (or version 1.3 or above – not out at the time of writing). The current implementation only supports MySQL and PgSQL at the moment so you will also need one of these 2 databases in order to follow the guide.

The first thing we need to do is to create a simple controller to run our tests from. Therefore create a new controller in your protected/controller/ folder. In this example I will use the controller “DatabaseController”. Now enter the following into the controller:

<?php
class DatabaseController extends DooController {

	public function updateDatabase() {

		echo '<h1>Update Database to Head</h1>' . PHP_EOL;

		/* DB Updater
Read More...

Moving protected folder outside your Web Root

In the latest trunk of the framework, we are able to move the protected folder in an application outside your web server root directory. Let’s say you have a structure as below:

www/
    superapp/
        proctected/
            index.php
            global/

To move it outside the WWW folder:

     superapp/
        proctected/

    www/
        superapp/
            index.php
            global/

Just change the configs after you move your files, SITE_PATH setting

//original
C:/wamp/www/superapp/

//changes
C:/wamp/superapp/

If you don’t wish to keep the name protected and wanted everything under superapp, try this:

    superapp/
        view/
        controller/
        .....
    www/
        superapp/
            index.php
            global/

Add on a new setting to common.conf.php, PROTECTED_FOLDER:

$config['PROTECTED_FOLDER'] = '';
Read More...

DooMailer learn how to send emails with new DooMailer class

In this tutorial we will learn to send emails, I just finished first version of DooMailer, it starts with calling DooMailer class:

$mail = new DooMailer();

You can add charset in constructor of DooMailer, default is utf-8.
Everything is pretty easy here is the code:


$mail = new DooMailer();
 $mail->addTo('yyyyy@yyyyy.yyy');
 $mail->addTo('xxxx@xxxx.xxx', 'John Smith');
 $mail->setSubject("This is test subject!");
 $mail->setBodyText("This is plain text body");
 $mail->setBodyHtml("<b>This is HTML body!</b>");
$mail->addAttachment('/var/web/files/file1.jpg');
 $mail->addAttachment('/var/web/files/file2.zip');
 $mail->setFrom('doo@xxxxxxxx.xxx', 'DooPHP ');
 $mail->send();

*** Added new option in setSubject function for forcing encoding of subject:

$mail->setSubject('subject of mail', true);

So as you can see everything is pretty easy, you add to add html body or text body and you can add attachments, when you are adding attachment you just provide link to the file on your website.
And then just do send() it returns true if mail is sent and false if not.

Read More...