Chapter 9: Silva

In the good old days of Curry cms when Flexigrid was the only framework available to construct backend modules, code maintenance was a pain. We would spend a lot of time writing these large complex backend modules with volumes and volumes of code. Most of the code was repetitive and we would end up doing a lot of copy pasting. This resulted in bugs since we would sometimes forget to update small details like the primary key of form actions and things like that. Hence, to make life easy for us and to alleviate the repetition problem, I wrote the Silva framework. I will not cover all the concepts of Silva in this book. You will have to refer the Github wiki for documentation. Silva "inspired" the ModelView framework. Hence, many of the concepts that I have covered in the ModelView framework are applicable to Silva. For example, we have a Curry_Form_ModelForm in the Curry core. This idea was taken from Silva. In the Silva framework, we have Silva_Form which behaves exactly like the ModelForm. Why was Silva not put into the core? That's because I wanted to keep Silva as a third party contribution package. Besides, it's not a good idea to stuff every thing into the core. The idea was to keep the core light-weight. After all, not every project was complex and required the complexity and functionality of the Silva framework. In a small campaign project, which had one or two simple backend modules, Flexigrid would suffice.

The main idea of a Silva backend module was "chaining views". You can visualize a backend module as a collection of views, such that one view "chains" to another view. The Link button is the "gateway" to the other view. This means that if I want to go to another view, I select a record in the grid and click the Link button. Every view in Silva is represented by a Silva_View object. The Silva_View class is abstract so you will need to subclass it. The subclass defines the type of view or rather what the view displays. For example, if you want to show a grid (i.e. table of data), you would instantiate Silva_View_Grid. If you want to show a view of only one record as in a form, you would instantiate Silva_View_ActiveRecord. If you wanted to show some arbitrary HTML content like a Google map in a view, you would represent the view by Silva_View_Html. If you wanted to show something else in your view, something I cannot think of right now, you subclass Silva_View and define your own custom view.

Let's create the Quotes module in the Silva framework. You will need to download the package from Github and copy the files to the correct paths. Refer Github for installation instructions. Create a new backend module file named QuotesSilva.php. Paste the following code into the file:

<?php

class Project_Backend_QuotesSilva extends Silva_Backend
{
    public static function getGroup()
    {
        return 'Demo Flexigrid';
    }

    public function __construct()
    {
        parent::__construct();
        $this->setViews(array(
            new Silva_View_Grid('Quote', null, $this),
        ));
    }
}

Now test your module in a browser. Does it work? Yes it should! The Add, Edit and Delete functionality should be working. Besides, the form is displayed smartly too. Do you see the relationships showing correct data in the dropdowns? What about the timestampable behavior. Those fields aren't showing? They should not show because Propel will automatically update them.

Silva is smarter and better than ModelView when it comes to handling complexity, especially when you work with view filters, internationalization and some more advanced Propel concepts such as Class table inheritance. However, Silva has a number of overheads. It tries to be "smart" everywhere. Hence, it consumes more memory and processing power than ModelView. Besides, it is a framework restricted to the Flexigrid and likewise is rigid. It lacks all the visual appeal of the ModelView framework.

I have written the Quotes module in the Silva framework with all the functionality available in the original module that we wrote on the ModelView framework. You can compare the code in the demo project.

Now that we are familiar with all three backend frameworks, let's go ahead and learn some more advanced concepts. It will now become easier for us to compare these advanced topics in both the ModelView and Silva frameworks. In the next chapter we shall learn about view filters and how to utilize them.

results matching ""

    No results matching ""