My first introduction to MVC was with Cocoa and Objective-C (yes I'm a Mac user), so to me the whole point of MVC to me is that the controller should contain all the logic in between the model and view. Which is what I am trying to figure out if I can do with the ZF MVC. I've read the Getting started with Zend Framework PDF from the other day and I am still don't know if I can do what I want to do. I'll figure that out though. :-D

I essentially have a template.

header
left right
footer

The left contains 2 box areas, the right contains 2 box areas.

in my index.phtml  so far I have


<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('footer.phtml'); ?>

I was thinking

<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('contentMain.phtml'); ?>
<?php echo $this->render('footer.phtml'); ?>

The contentMain.phtml would contain the left and right areas.

I then want to be able to configure if the left section has box one displayed, box two displayed or both boxes displayed, same in the right side.

I just haven't figured out the right way to do it yet. I can either make my views very basic and read in the other sections via my controller class, or put logic in my phtml files which I would rather avoid.

I had a 3hr instant messenger debate about this very topic with an ex- coworker of mine.

Maybe something that would be nice to add is a modification to the render function.

$this->render('contentMain.phtml', true);
$this->render('contentMain.phtml', false);

That way you can control what is rendered from the controller, just by passing the right variable. Obviously this would be defaulted to "true". It would be nice for turning on and off components without having to write in logic in the view.

Just a thought.

James





On May 29, 2007, at 8:14 PM, Maurice Fonk wrote:

You can use Smarty and separate logic from design. Smarty really does fit in with the MVC model just fine, and takes over the View part with elegance. In fact, I believe that using a template engine will keep you from using logic in you views. Where php pretty much allows you to do everything you want, Smarty syntax doesn't.

I will now shamelessly plug a blog post of my own hand on Smarty and the ZF:
http://naneau.nl/2007/05/10/smarty-and-the-zend-framework/
it deals with the problem described by Gunter, about either extending Zend_View or implementing Zend_View_Interface.

Thing is, a lot of people are quite comfortable with Smarty, and it should at the very least be possible to use it with the framework. I don't see how it would violate the MVC pattern.

MF

James Andrews wrote:
Isn't using Smarty on top of MVC kind of counter intuitive. You should be using one or the other, not both. Any template engine that has logic in it is pointless the entire idea is that you do all your logic in the php and then the template engine should just displays the results. Then again I am quite anti smarty. (sorry big pet peeve of mine.)

James




On May 29, 2007, at 7:02 PM, Gunter Sammet wrote:

Matthew, thank you for your hard work and prompt responses. Here a few lines on my experience so far:

I am pretty new to ZF and MVC. On top of that I want to implement Smarty as the template engine. Been spending a few days on reading the documentation, what I could find on the Internet and playing around with the zfdemo code. Still don't get the whole picture but it makes more and more sense. Figure it will take me another few days of playing around to understand it a bit more. Managed to get some views working through piecing together code pieces from several tutorials and the zfdemo app. I followed the emails in the last few weeks, so I knew that there were some changes that are not compatible. That's why I upgraded today to 1.0. This broke my setup with the Smarty view, injecting templates out of a template directory. Since I am still not very proficient in debugging the ZF and I had $frontController->throwExceptions (true) set, I didn't get the error message that it didn't find 'index/index.phtml'. It took me a few hours to figure it out and I am thinking about my potential new structure. Besides the above, I had to change my smarty view to use "extends Zend_View_Abstract" instead of "implements Zend_View_Interface" which required me to declare the "_run" method. For now till I have my new template structure, I managed to bypass the auto view settings by using the following lines of code; $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$viewRenderer->setViewBasePathSpec($tmplPath)
             ->setViewScriptPathSpec('landing.tpl')
             ->setViewScriptPathNoControllerSpec(' landing.tpl')
             ->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
//Zend_View_Controller_HelperBroker::addHelper($viewRenderer);
NOTE:
=====
-->The sample code at http://framework.zend.com/manual/en/ zend.controller.actionhelpers.html#zend.controller.actionhelpers.vie wrenderer <http://framework.zend.com/manual/en/ zend.controller.actionhelpers.html#zend.controller.actionhelpers.vie wrenderer> (paragraph 7.9) wants you to implement Zend_View_Controller_HelperBroker::addHelper($viewRenderer);. However, I didn't find a HelperBroker there. Seems to be the Zend_Controller_Action_HelperBroker that is meant there.

Your changes make sense and should make the default setup easier. I will try to implement it as close as possible to be open for future refactoring. That's why I didn't use the
|$front->setParam
('noErrorHandler', true);
|
If I understand it correctly, that should have solved my problem without changes. A good read for it is the migration page ( http://framework.zend.com/manual/en/ zend.controller.migration.html#zend.controller.migration.fromzeronin ethree)

Hope these lines help some other users to figure it out a bit earlier and for you to understand the issues ZF newbies may face.

Gunter



--
Maurice Fonk

[EMAIL PROTECTED]
http://naneau.nl/

Scio me nihil scire


Reply via email to