how to get dynamic URL like mydomain.com/username using zend framework

前端 未结 6 1609
孤街浪徒
孤街浪徒 2020-12-15 15:02

I am developing an application using zend framework. In the application I have to provide a URL for each user like mydomain.com/[username] then public will be able to view

6条回答
  •  一整个雨季
    2020-12-15 15:32

    Seems to me that the difficulty here is that you are using the same url scheme:

    http:/example.com/something

    to represent two types of actions:

    1. If "something" represents a user name, consider this a request to controller=user, action=viewProfile, param=something.
    2. Otherwise, consider this to be a standard request to the controller SomethingController

    This seems a bit odd to me. I'd prefer to put the user requests under a different url scheme, like:

    http://example.com/user/bob

    where standard routing rules can apply. Want to avoid the risk that a user registers with a name that conflicts with one of your static controllers. Of course, you could maintain a pool of "reserved" user names for your static controllers that would be unavailable for users to choose.

    But if is really is the requirement that the same url format must be used for both types of requests, then I would do the following: route all requests to something like TrafficCopController with an action directTrafficAction(). The action could test - probably via db query - if the passed "something" parameter represents a real user. If so, then forward the request to controller=user, action=viewProfile. Otherwise, forward the request to controller=something, action=index.

    See what I mean?

提交回复
热议问题