Hi Folks,

I've got a short (well, maybe middle ;-)) question regarding my MVC setup.

I set up a FrontController (Bootstrap File) with RewriteRouter as
suggested in
http://framework.zend.com/wiki/display/ZFDOCDEV/5.1.+Getting+Started and
 http://framework.zend.com/wiki/display/ZFDOCDEV/5.3.+Provided+Subclasses
and configured some static and dynamic routes. The ActionControllers get
called and everything is fine so far.

Now I'd like to render some content using the Zend_View class. As I have
to setup the view path each time, I came up with the following idea:

First I create an instance of Zend_View in the FrontController /
Bootstrap file and initialize and register it as follows:

$view = new Zend_View();
$view->setScriptPath(PATH_VIEW);
Zend::register('view', $view);

Then, in the ActionController I use the view via

$view = Zend::registry('view') ;
$view->baseUrl = $this->getRequest()->getBaseUrl();
$this->getResponse()->appendBody($view->render('index.php'));

This works pretty well, but every time I look at the code I have to
think "there must be a better way of doing this". I think the main
problem is the setScriptPath call which has to be made in each
ActionController otherwise.

So far for the first problem: Do you know any better way to use the
Zend_View class? How do you render your content?

Next is a topic also dealing with Zend_View. As we all know a page
doesn't simply consist of a static frame and some dynamic main content
only. So, I'd need a way to render several "blocks" with Zend_View and
compose these into a base template. I had two different approaches:

- Render everything into a big $view->content variable and output
$this->content in the template.

- Setup a $view->contentTemplate variable which indicates which
sub-template to use and set all required data in the main template.

I hope you know what I'm talking about because the code examples for
these points could get pretty long.

Also these approaches don't deal with additional content like dynamic
navigation or login/logout in the margins (say non-main-content-area).

Again the question is: How do you handle such rendering in your
applications?

Last but not least there's a topic I don't have any idea for: The model.

As far as I got it, ZF only provides basic database functionality.
Should I handle my database code all in the ActionControllers or create
complete self-contained data objects like say propel does (there's a
word for these, but I can't remember right now ;-))? Let's use an easy
example (example! ignore the security holes please ;-)):

$db->query("SELECT Id FROM User WHERE Password = '$password' AND
Username = '$username'");
...
$db->query("UPDATE Online SET LastAction = NOW() WHERE UserId = $id");

or

$user = $userFactory->getUser($username, $password);
$onlineFactory->getRecord($user->getId())->setLastAction(time())->save();

Up to the point where it get's really dirty, I'd favor speed for clean code.

Are there any tutorials  or documentations available on how to handle
the model part in a somehow abstract but not completely slow way?

At last I'd like to apologize because I'm pretty sure these or similar
questions were already asked and answered in the past, but I simply
can't find some matching documentation. In case you know of any
tutorials or links on the mentioned topics, I'd be glad to hear from you :-)

Thanks a lot in advance,
yours Sascha

Reply via email to