Author Archive

DooFlashMessenger

Hi guys, DooFlashMessenger is here, in this tutorial I will explain you how can you use it with just 3 lines of code. Same thing you have in class comments.

Well lets begin, we start with calling class:

$flash = new DooFlashMessenger();

Now we must give access to DooFlashMessenger from view, we do that like this:

DooController::view()->flashMessenger = $flash;

When we can access from view to flashMessenger we can display messages from flashMessenger, we do that with displayMesssages() method.
Here is the code you need to have in your template file:

$flash->displayMessages();

Thats about it, now you just need to add some message to flash messenger, message will be stored in session, with next execution of DooFlashMessenger class messages that are stored in session will be printed with displayMessages() method. Calling displayMessages() method will echo all messages that are stored.

Adding messages to flashMessenger is done by calling method addMessage:

$flash->addMessage("This is just test message");

That’s it if you have any questions please do ask.

More »

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

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.

More »

Concept of how to work with DooFramework

Ok in this article I will show you how should you work with DooFramework, when I am making website I like to have one super class that extends DooController class and in constructor of that class I will add all stuff needed for my application, so lets make that class, we should name it for example CoreController :)

<?php

class CoreController extends DooController {

 /**
 * Current URL
 */

 protected static $_currentUrl = null;

 /**
 * Instance of Doo::db
 */

 protected $_db = null;

 /**
 * Translator
 */
 protected $_translate = null;

 /**
 * Instance of Doo::cache
 */

 protected $_cache = null;

 /**
 * Base path of application
 */

 public $_basePath = null;

 /**
 * Instace of DooSession
 */
 public $_session = null;

 /**
 * Instance of DooAcl
 */

 public $_acl = null;

 /**
 * Host
 */

 public $host = null;

 /**
 * Js path
 */

 public  $jsPath = null;

 public function __construct() {
 $this->_basePath = Doo::conf()->ROOT_DIR;
 // add some globals that we need
 $this->_db = Doo::db();
 $this->_view = DooController::view();
 $this->host = Doo::conf()->host;
 $this->_view->host = Doo::conf()->host;
 // ACL
 $this->_acl = Doo::acl();
 // add sessions
 $this->_session = Doo::session("mywebsite");
 $templateVariables = $this->getSettings();
 // session
 $this->_view->_session = $this->_session;
 $this->_cache = Doo::cache('apc');
 $this->jsPath = $this->_view->host . 'static/js/';
 }

 /**
 * Before run method
 */

 public
More »