开发者

Browser Detection and Zend MVC

I have a PHP application using Zend MVC framework. The entry point for every request to the application is in /public/index.php.

I have a Browser class that has functions to check if the user's browser is compatible with application or not.

My dilemma is, index.php is executed for every controller call. So there are chances that this file gets executed multiple times within the same page and hence re开发者_运维知识库direction becomes an issue. What's the best way to solve the looping issue?

Thanks


Regarding your "dilemma", which sounds like a different issue altogether, I would really avoid calling index.php on every controller call. That's your fundamental issue I think. If you must, I suppose you could use the Session to track a user's calls to the various pages.

But index.php should be an entry point ONLY, and any further code logic that gets executed should remain completely unaware of its very existence.

Regarding Browser Detection:

To my knowledge there is currently no established ZF component that determines the browser for you. There are two ways to go about this. One is to check the browser based on the User Agent string using $_SERVER["HTTP_USER_AGENT"].

The other way, of course, is client-side detection. Most JS libraries provide methods to do this; as most jQuery users are aware jQuery has deprecated its jQuery.browser features, but they are currently still available.

As indicated at http://docs.jquery.com/Utilities/jQuery.browser however, it is recommended that in place of client-side browser detection, you check for the specific features you need.


You should do it in a front controller plugin. There are several method which are called in dependency on the point of the dispatch process you are.

look at http://framework.zend.com/manual/en/zend.controller.plugins.html


$i = 0;

if ($i === 0)
{
   // put everything currently in index.php into here

   $i++;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜