Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Hi I realy like how magento creates it's view. It's not standart MVC like Codeigneter or Ruby on Rails. Magento has Block and Template. So I have created an architecture like this. I have layouts (xml files). And views(phtml files).

Layout example.

<data>
    <register>

        <referense to="master">
            <action method="removeBlock" value="notice" />
        </referense>
        <referense to="master">
            <action method="setTemplate" value="page/default.phtml" />
        </referense>

        <referense to="head">
            <action method="addCss" value="css/form.css"></action>


        </referense>

        <referense to="master">
            <block name="content" type="Customer/FormBlock" template="customer/form.phtml"></block>
        </referense>


    </register>



    <activate>

        <referense to="container">
            <action method="setTemplate" value="customer/activate.phtml" />
        </referense>
    </activate> 

</data>

The controller.

class CustomerController extends ActionController
{ 
  public function indexAction()
  {
   //....
  }

 public function registerAction()
 {
    //....
  }

 public function activateAction()
 {
   //....
 }


}

So when user calls "activate" action , it will render the view in <activate/> tag. if there is no such tag , it will render for <default/> tag.

Is this pattern useful for small applications like Simple Blog ?. Because it's takes more time for development but the applications are very dynamic. May be there are more useful patterns like this one, if there are , please provide me. Thank you.

share|improve this question
    
for simple blog, no, probably not -- i dont think its necessary. On a side note, the block and template separation can be achieved using hMVC, which is MVC in the sense that there are traditional model view controllers and then you can load them independently into other MVCs as blocks.. which is what Kohana is all about. I hope you find that useful –  Kristian Mar 22 '12 at 22:20
1  
The 'Magento' way is overly complex, really built on being able to override everything while in practice this only makes things needlessly complex... You'll do a lot better with something simpler... –  sg3s Jun 25 '12 at 10:58
    
The answer is no. It is always good to avoid the complexity of framework/pattern for a small application unless you are doing it for practice. –  Kinjal Dec 20 '12 at 9:10
add comment

migrated from stackoverflow.com Jun 25 '12 at 12:39

This question came from our site for professional and enthusiast programmers.

1 Answer

The problem I see for simple apps is the cost of overhead for being able to overwrite anything as well as combining all the xml files into a huge xml file (takes a lot of memory and time). If you simplify the layout by using direct class names(not allowing for overwriting) as well as possibly using simple multidimensional php arrays instead of complex xml trees I don't see why that concept couldn't be applied to a smaller project.

Just try and remember to only add complexity as needed so as to keep your application more readable and "debug-able", especially if someone else (including you 10 years from now) has to read or modify it later. Make sure you create documentation of what your xml or array or json or whatever is supposed to look like and possible values. Don't just add functionality because you think you'll use it later, wait till later to add it because often you either never use it or find a better solution when the situation arrises.

If you are modularizing your code I would also provide some way of caching your configuration/layout files so you don't have to generate them every time. As well as a way to cache individual blocks so that if possible you dont have to regenerate them every time(like a category listing block,etc).

TL;DR make things with only the complexity needed for the application and you should be fine.

HTH

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.