Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-01-2008, 03:52 AM
BJM BJM is offline
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default Use only one controller and view script?

Hi all,

I've read some stuff on modules however I'm new to Zend Framework and MVC, and just don't seem to be understanding it with regards to normal websites. Is there a way to have a default controller that handles all http requests?

I'm creating a very simply CMS that allows a user to add/edit/delete pages (and child pages). I want a module setup to handle the admin area (mysite.com/admin), and within this admin area I want a full application for adding content. This seems to be the easy part. The part I don't understand is how to make every other type of request (i.e. mysite.com/abc, mysite.com/123, mysite.com/abc/def/ghi, etc) use a default controller and view script. Other than the admin area, every page should work exactly the same; the only difference being the file it pulls content from, which will depend on the URL being requested. Advice would be great.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-01-2008, 06:15 AM
Junior Member
 
Join Date: Mar 2008
Location: BC
Posts: 6
Default

I could be wrong but what it sounds like is you want a standard 'template' for every page?

If so, I would suggest checking out the Zend Framework Webinars

In particular there is one called 'Zend_Layout and Zend_View Enhancements'. This will show you how to use the new ZF 1.5 Layouts to have a standard layout with view content being inserted in it.

Also, check out: PHP VIDEO TUTORIALS FOR WEB DESIGNERS. There are some good screencasts by Jon Lebensold. I believe one touches on the new Layout features. It's a good series to go through.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 01:31 PM
BJM BJM is offline
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

Thank you for the reply Toppy, however I believe you misunderstood. I actually have viewed the new layout webinar and do plan on using that approach, however my question was related to the framework files (mostly controllers), not just the layout. For instance, take the following URLs:

mysite.com/index
mysite.com/about_us
mysite.com/services/
mysite.com/services/service1
mysite.com/services/service1/features
mysite.com/services/service2
mysite.com/services/service1/pricing

My understanding of Zend Framework and MVC is that I'd need a controller for index, about_us, and services. In addition, I'd need view scripts for service1 and service2. Anything after the view sript is supposed to be variable/value pairs, so I don't even know how that would work (third, fourth, fifth level directories), but it's besides the point. The problem is that with a CMS I have no idea what pages the user will create, and how many child pages each page will have. Let's say a user wants to create two new pages, one being mysite.com/contact_us, and the other being mysite.com/services/service3. From a coding standpoint, do I need to dynamically create a new controller and view script for the contact_us page, and dynamically create a new view script in the already created services view script area for service3? I plan on storing the actual page content in a database or XML file, therefore the view scripts won't even contain the main content, so it would be nice if I can have one controller and view script handle everything.

BJM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-01-2008, 01:49 PM
Ewok's Avatar
Junior Member
 
Join Date: Mar 2008
Location: Colorado SPrings
Posts: 16
Send a message via MSN to Ewok Send a message via Yahoo to Ewok
Default

Most systems use something like this...
mysite.com/cmscontroller/id/1234

So the index view of cmscontroller displays the DB entry with the id of 1234
__________________
Give all victory and gain to others
Take all defeat and loss upon yourself
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-01-2008, 08:20 PM
BJM BJM is offline
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

hmmm .. Thank you for the feedback, unfortunately I was hoping for a much slicker method. Using parameter/value pairs (mysite.com/cmscontroller/id/1234) is good for viewing things like news items or article items, however I don't like that approach for actual page names. In my experience clients can be picky about their URLs, especially when they advertise them. I think people may complain if I tell them to print "mysite.com/services/id/1234" on a brochure instead of "mysite.com/services/service1/features/".

In addition, this wouldn't resolve the problem of a site with 20 or 50 (although that may be unrealistic) "top level" pages (mysite.com/a, mysite.com/b, mysite.com/c, mysite.com/d, etc). It seems odd that I would be forced to create a different controller for all of these pages even though the logic for them will be the exact same. Either I'm misunderstanding (which I admit is probably the case), or MVC is better left to web applications, not basic websites with tonnes of pages. Separating content from process is great, but now I'm stuck with choosing between unfriendly URL's, or having redundant controller files that all do the same thing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-03-2008, 01:44 PM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

Or you could use a custom route. Look into Zend_Controller_Router_* and I'm sure you will find what you need.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-03-2008, 04:49 PM
BJM BJM is offline
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

Thank you Leif.Högberg. This may be exactly what I'm looking for. I'll look into it further.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-05-2008, 08:12 PM
BJM BJM is offline
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

If anyone is interested, I've been able to solve the issue using routes:

PHP Code:
$router $front->getRouter();
$router->addRoute(
    
'default',
    new 
Zend_Controller_Router_Route('*', array(
        
'controller' => 'index',
        
'action'     => 'index')));
     
$router $front->getRouter();
$router->addRoute(
    
'admin',
    new 
Zend_Controller_Router_Route('admin/:controller/:action/*', array(
        
'module' => 'administration',
        
'controller' => 'index',
        
'action'     => 'index'))); 
Not sure if this is the best approach since I'm new to Zend Framework ... but it works . Thanks for the replies.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-16-2008, 03:41 PM
Junior Member
 
Join Date: Apr 2008
Posts: 6
Default

I'm looking at doing a similar thing and was thinking of setting up a StaticController which would hold all the static pages within /app/views/scripts/static/.

I was then going to setup static routes for each one, you how ever have done it for all URLs how did you go about flagging Error pages?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:47 PM.