Developing New Paths

The Mojavi Project

Archive for March, 2010

March-26-10

Global template

posted by admin

Component Driven Global Template System

PLEASE NOTE: the approach explained below has a few drawbacks, mainly that the execute method of action always need to be executed for the output to appear in a template. I’ve decided to use a different solution to the problem. We will be incorporating online surveys as new versions are created in order to keep the development community engaged in the entire process.

Like many of us I’ve been struggling with a global template approach to Mojavi 2.0 site development for a while. Most of the suggested solutions in the forum still require a fair bit of code duplication, so I tried to come up with my own idea.

I wanted a template “system” which lets me define one or more global templates which integrate the output of multiple actions into one single html page. Mojavi already has the basic tools for this: the ActionChain and Filter classes.

Used Classes

Here is the code to all classes used by my system

TemplateFilter.class.php

/**
 * This filter implements global templates
 * Used in combination with the AggregateAction class
 */
class TemplateFilter extends Filter
{

    function execute (&$filterChain, &$controller, &$request, &$user)
    {
        static $loaded = false;

        if(!$loaded)  //only load once!
        {
            $loaded = true;

            //set up main renderer and store it in the request instance
            $mainRenderer =& new Renderer($controller, $request, $user);
            $request->setAttributeByRef('mainRenderer',$mainRenderer);

            //contuinue processing the filter chain and store the output
            //in $body
            ob_start();
            $filterChain->execute($controller, $request, $user);
            $body = ob_get_contents();
            ob_end_clean();

            //mainRendererTemplate will only be set if the execute method
            //of the AggregateAction class was executed and there were
            //additional actions to be rendererd
            if($request->hasAttribute('mainRendererTemplate'))
            {
                //if the mainRenderer was used, add body to the renderer
                //and output to client
                $mainRenderer->setTemplate($request->getAttribute('mainRendererTemplate'));
                $mainRenderer->setAttribute('body',$body);
                $mainRenderer->setMode(RENDER_CLIENT);
                $mainRenderer->execute($controller,$request,$user);
            }
            else //otherwise, just echo the html to the browser
            {
                echo $body;
            }
        }
        else
        {
            $filterChain->execute($controller, $request, $user);
        }
    }
}

AggregateAction.class.php

/**
 * An easier way to add action chains to Actions
 */
class AggregateAction extends Action
{
    var $actChain = null;
    var $actNames = null;

    /**
     * Adds an action to the aggregate action chain
     *
     * @note params like ActionChain::register()
     */
    function addAction($name,$module,$action,$params = null)
    {
        if($this->actChain === null)
        {
            $this->actChain =& new ActionChain();
            $this->actNames = array();
        }

        $this->actChain->register($name,$module,$action,$params);
        $this->actNames[] = $name;
    }

    /**
     * Default template name
     *
     * @return string the template name
     */
    function getMainRendererTemplate()
    {
        return 'main.php';
    }

    function execute(&$controller, &$request, &$user)
    {
        //only execute this if we render to client
        if($controller->getRenderMode() == RENDER_VAR)
            return;

        $renderer =& $request->getAttribute('mainRenderer');

        if(!($this->actChain === null))
        {
            $this->actChain->execute($controller, $request, $user); 

            foreach($this->actNames as $name)
            {
                $renderer->setAttribute($name, $this->actChain->fetchResult($name));
            }

            $request->setAttribute('mainRendererTemplate',$this->getMainRendererTemplate());
        }
    }
}

MainTemplateAction.class.php (Example template action)

class MainTemplateAction extends AggregateAction
{

    /**
     * Initialize is used to add actions to the action chain
     *
     * @note It has to return true, otherwise processing will not continue
     */
    function initialize(&$controller,&$request,&$user)
    {
        $this->addAction('login','Default','Login');
        $this->addAction('nav','Default','MainNavigation');
        $this->addAction('cart','Cart','Show');

        return true;
    }

}

That’s all there is to it. The TemplateFilter has to be registered in the global filter chain and all my actions that might at some point be used to output the “body” into the main template extend MainTemplateAction.

The views don’t have to be modified, all the work of getting the renderer output into a global template is handled by the AggregateAction and TemplateFilter.

Setting the global template name in an Action with the getMainRendererTemplate() method is probably not very clean, but it all works like a charm for me and takes away a lot of the hassle of global templating with Mojavi.

The global renderer templates have to go into the YOURAPP/templates directory.

Please feel free to give comments on my approach in this forum topic.

March-25-10

Get Superb Hosting

posted by admin

If you are looking to switch hosting providers or just getting into the market then there are various questions you need to consider when considering managed hosting. How much server space you will have? Can you upgrade to a dedicated server if your business grow or do they just shut down your account? What types of servers and operating systems that are used? So they have redundant backups? How many domains and email addresses can you host on one account? And how much bandwidth can you receive without being penalized? Companies like Superb Internet is set up to help small to medium businesses and help you grow your capacity as your online presence expands. You can select a wide range of dedicated servers in order to make are that you have complete control of your hosting platform. This can also be beneficial for search engine marketing and quick growth phases that your site may experience.
And if you already own your servers and are looking for a secure and reliable storage site then Superb Internet offers state of the art colocation services with an array of security services, and redundant back up services you know that your prized hardware and data are being taken care of.

March-19-10

Vodafone provides SIM only deals

posted by admin

Vodafone has recently decided to focus entirely on the popular Vodafone SIM only deals. The only reason for this perhaps is the amazing Apple innovation. Yes, you guessed it right, it’s the iPhone. While more and more people in the UK are hankering to get an iPhone for themselves, it is time for Vodafone to provide their customers with deals which might just make them switch networks? While it is too early to make any kind of prediction it is always a great idea to look into the reasons behind the iPhone’s success. It is extremely jam packed with the best of Apple designs, not to mention and entire range of apps. Also this beauty is sure to put a lot of other phones to shame because of its sleek design and appeal. So Vodafone has realized that it is high time that they cashed into this entire boom of the iPhone market with the iPhone SIM Only deals and this will surely help in creating a better idea of what is required and what is relevant. Of course the competition between different networks has possibly forced Vodafone to take this step towards better network deals. However it is always excellent news for all their customers who are looking forward to all types of amazing deals.

The best part is that the customers have an entire gamut of excellent options which has made it so incredibly important. The focus primarily needs to be on an extensive range of deals which is sure to put Vodafone on the list of the most coveted network services. Apart from the lowest plan which comes to around ten pounds, Vodafone will offer free text messages to all customers from then on. This is surely the best way in which different types of deals can be very well dealt with and it also provides an extensive range of offers and deals to all the customers. It is always a good idea to take a look at the best SIM deals available which helps customers understand the entire process better. Customers can visit the Vodafone website which is sure to help them and guide in all types of amazing deals that will help in an extensive range of deals and a whole lot more. The idea is to get best types of offers which can provide people with more and better ideas of what is important. Also this is an important plan by Vodafone to get better customer following.

It is possibly the best idea for the customers to sign up for a twenty five pound per month offer which promises 900 minutes of free talk time. This is obviously an excellent deal for people who are constantly making calls and need plenty of talk time in their phone. So there is no fear of running out of talk time which is always the best idea when it comes to these plans of getting amazing deals with Vodafone and customer care. It will also help provide an extensive range of data that is sure to get customers going for better Vodafone networking options.

March-19-10

Getting a good nights rest

posted by admin

Do you have trouble sleeping? I know not getting in a good night sleep can cause us to have a bad day. Instead of trying to take all of the sleep aid pills that are available, consider looking at sound machines. A sound machine can help you achieve a deeper and more relaxing sleep overnight. This is a more natural way of getting different sounds, that causes the brainwaves to match the sounds you are hearing. Find the sound that best suits you, it might be crickets chirping away that is combined with the NASA authentic recordings from Jupiter. This is a much better way of falling to sleep without the use of medications to do it. There is also different timers you can set with your sound machine, so it will automatically shutoff when you want it to.

These have become so popular that some hotels offer a white noise machine in their hotel in order to help their guest get the best nights sleep possible. For those of us who travel trying to get a comfortable and get a goods night sleep in a hotel can be difficult. Just because there are so many foreign noises that you are not used to and you never know when you will be close to lobby or your neighbor is a night owl that loves to hear the TV at its highest volume. The newer sleep machines can help you get the rest you need for that important meeting for the next day. Try one of these sound machines and start taking advantage of the 23 years of scientific study that has went into these sound machines.

Tags:
March-11-10

WoW gaming is growing

posted by admin

The online multi-player online game World of Warcrafts has grown from a small internet novelty game to a huge forced to be reckoned with by other multi-player games. So much so that World of Warcrafts accounts are now being bought and sold for very good money. Because of the nature of the game it can take several months to build up your characters that there has become a large market for those with advanced games and characters to sell wow accounts for several thousands of dollars. People will spent countless hours playing Wow and take their roles and characters very seriously and the game play is quite addictive. The game and selling of accounts has even gotten so popular that there are now scam email that even I have received asking for you to verify your WoW account details or you account and all character points will be lost. This goes to show that there is big money to be had if you gain control of someones World of Warcrafts account and they have several advanced characters.

That is why online sites like Virtual Barrack have tried to create a safe and secure place where you can find wow accounts for sale or even offer your own account for sale. They have developed their site so that you can look for the level of player and specific characteristics in order to add them to your own account. So if you are looking for a Level 80 Male Tauren Druid then you may have found your source. They provide a 100% account protection gurantee so that you do not taken for a ride.