开发者

Yii generate errors from parent controller

I just started using Yii, coming from Codeigniter (CI). I'm trying to set up a situation where the application will check a users credentials before they can even access the site. In CI, I would create a parent controller, put my checks in there, and then inherit that parent controller. I've been trying to do the same thing with Yii, but with no luck.

I first created an init() method (for some reason I can't put the code in a __construct() method). I then perform my check, which works fine. I can 开发者_如何学编程throw a new CHttpException, but that looks ugly. How do I use Yii's built in error handling to accomplish what I want to do?


For simple login rules you should just implement the 'accessControl' filters from Yii see Yii documentation on authorizations.

Another way would be to throw the Exception like you already did, and write custom Http error views, place it in the yerfolder/protected/views/system/ (see the yii/framework/views directory for examples)


I solved this by sending the error to the site/error view and then calling Yii::app()->end() to keep the child controllers from loading.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜