Page 1 of 1

MVC(Zend) & AJAX

Posted: Sat Jul 14, 2007 9:28 pm
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???

Posted: Sat Jul 14, 2007 9:59 pm
by Selkirk
This is a big concern of the guys that I've talked to who are actually using ZF.

Posted: Sun Jul 15, 2007 3:17 pm
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.

Posted: Mon Jul 16, 2007 3:24 am
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.

Posted: Mon Jul 16, 2007 8:20 pm
by alex.barylski
Hey thank Maugrim. I read those articles you have posted on Zend. Good job. ;)