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.viewrenderer <http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer> (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.fromzeroninethree)

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