MVC(Zend) & AJAX

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

MVC(Zend) & AJAX

Post by alex.barylski »

Assume a Controller such as:

Code: Select all

Contacts{
  create();
  update();
  delete();
}
Now assume Contacts derives from a master controller which initializes the master view and menu views...

If I wanted to use AJAX to create() a contact, I would be instantiating alot of baggage for nothing as all that is needed is a simple DB query.

Do you create a new controller which uses the same model but without overhead of views, etc???
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Post by Selkirk »

This is a big concern of the guys that I've talked to who are actually using ZF.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Yeah, it makes sense to write another base controller. Controllers are going to be tying together presentation and your model, so I think with a lot of frameworks you would use another controller since you would be ditching most of the presentation and instead just returning data.

One thing that I have done in the past, since ajax ends up being controller-like sometimes, is to create a server side controller action that takes a model name, model method, and arguments as parameters. Then it checks to see if those are allowed to be called via ajax, executes the model method, then returns the data. This way you aren't writing a ton of controller methods that are just doing one call to your model.

Realistically though, I wouldn't worry about the overhead until it became an actual measureable problem.

edit: ignore my last line, I guess I would worry about it now as this would be something that would be hard to fix later.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Use another base controller which skips all the presentation setup. It can actually extend your Application controller - to allow everything else except view setup. You may also need to disable the ZF default enabled ViewRenderer Action Plugin which also does View setup.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Hey thank Maugrim. I read those articles you have posted on Zend. Good job. ;)
Post Reply