I'm trying to set up a yii frontend to an existing database. By dint of history, it has several tables with negative IDs - there's a nice set of consecutive IDs from 1, but then there are a large set with large positive and negative IDs. No, I don't know why.

When using yii to retrieve one of these records from a listing (all vanilla yii), the URL is something like http://myyiipath/index.php/houses/-75313. This then returns an error page saying "unable to find the requested action". It works, retrieving the details of the record, when given a valid positive ID.

I understand yii uses - as a separator when selecting an action, so I'm guessing the negative value is being interpreted as blank:id.

So can I either modify yii to use the default action (with the signed value) when no controller is specified, or can I direct the default action to some handler, or is it all a nightmare?

有帮助吗?

解决方案

You will have to change

<id:\d+>

to

<id:\-?\d+>

in your urlManager rules.

Example:

'<controller:\w+>/<action:\w+>/<id:\-?\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/' => '<controller>/index',
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top