Question

Is it possible to extend Yii URL routes and rules through a Controller on the fly, or by extending the CController class itself?

I am really stuck with this, have not tried anything.

How to do this in/with Yii?

Était-ce utile?

La solution

First you should be aware of what URL rules are used for:

  1. Parsing an incoming URL. The urlManager component resolves a URL to a route so that Yii can call the right action in a specific controller and module.
  2. Creating URLs from calls to createUrl() in your code.

Considering (1) above it is obvious, that you can not add URL rules in your controller if you want to use these URLs in your application. It's much too late, as Yii already has gone through the process of resolving a request to a route. Even if you'd only wanted to create URLs it doesn't make much sense as your application will never understand them.

The correct way to bring more dynamics into your URL parsing/creation is to use a custom URL rule class. In there you can write any code you want to create and parse even the most complex URLs. The topic is described in the manual.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top