Zend MVC Screencasts: Zend Layout, Controller, View and Db

by jon on March 25, 2008

I've put together a couple of Zend screencasts in an effort to explain some core concepts in Zend. I've entitled the series of three videos Working With Zend MVC and it's available free on Idea22. I've also included a sample project to get you started which you can also download.

Topics Covered:

  • Zend Framework Folder Structure
  • Zend_View and it's relationship to Zend_Controller
  • Zend_Controller and the management of form postbacks
  • Zend_Db Insert and Fetching rows
  • using Zend_Layout to build headers and footers using the Zend MVC model

I've posted the first video here. Comments are much appreciated!

{ 12 comments… read them below or add one }

Julian March 26, 2008 at 10:24 am

Nicely done!!

James Lin May 27, 2008 at 12:23 am

Hi Jon,

I’m getting the following error when I try to follow your instructions. I’ve tried using the .htaccess file you included, but it still doesn’t work:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

jon June 4, 2008 at 1:37 pm

Hi Ici,

looks like you’re missing index.phtml in the views/scripts/index/ folder

just create one… I’ll have to include that in my example.

also make sure that you have Options All set in your vhosts configration.

Good luck James!

Mehmet Ali June 10, 2008 at 1:41 pm

I have problem in this tutorial on Part – 2.
On time 02:01, there has been created a new.phtml file, and a link in article. But when I click to that link, o manually enter the http:/articlemanager/article/new to address bar, I can see the header and footer control but CSS doesn’t applied.

What is the problem???
Thanks.

jon June 13, 2008 at 6:11 am

Hi Mahmet, in the layout.phtml file, I’m assuming that you’re running the Zend Framework project on the document root:

this may not be the case for you. Worse comes to worse, I would suggest using a tool like the firefox web developer toolbar and view the CSS to see if its loaded.

Good luck!

tim September 3, 2008 at 10:26 pm

great video! helped a ton!

lkimme January 29, 2009 at 4:07 pm

Hi Jon, I like your screencasts a lot. Very, very helpful to me.
I’ve developed a problem when I try to use my layout.phtml file from a controller/subAction.
My layout.phtml file works fine if I try to render from a controller/indexAction function, but when I try to display from a controller/non-indexAction function the css files and image files that I link to all fail.

I am including files in my controller/init() method like this:

$response->insert(‘header’, $this->view->render(‘header.phtml’));

Again, it works fine in the controller/indexAction function, but not in the controller/non-indexAction function.

Thanks for any help.

jon February 2, 2009 at 10:32 am

Hi Ikimme,

you could try just using the ‘/’ (absolute path) as a starting point if your application is sitting on the root of your domain. another way is to use the $this->getBaseUrl() accessor as a way of making your paths absolute for loading images etc… you could look at this: http://www.scribd.com/doc/2302091/gettingstartedwithzendframework-150 as a way of doing it. Another way is just to set a variable in your registry with your absolute path and then call it using Zend_Registry::get(‘mypath’) or whatever.

Good Luck!

lkimme February 2, 2009 at 11:42 am

Thanks Jon, I was omitting the ‘/’. It works fine now.

Thanks again.

rags October 27, 2009 at 7:06 am

haii jon
I want to use include in layout.phtml to include another file,
could you please let me know how to use it.

jon October 29, 2009 at 4:42 pm

Hi rags,

you could just use include_once(‘layout.phtml’); if you wanted it to echo as is. Alternatively, you could write a view helper for part of the layout and include it as a plugin. There’s a tutorial on Zendcasts that I believe covers this.

Robert Kraig March 28, 2010 at 7:22 pm

I can’t seem to find your Part 2 of your tutorial on setting up the db portion with the form posting etc.

By the way, i appreciate your screencasts great deal.

Leave a Comment

Previous post:

Next post: