What Module Am I Using

I’m working on a site that has a frontend and an admin module. Both are currently using the same Models. I need to change the actionSearch() criteria depending on whether a user is looking at something and an admin is looking at it.

In Frontend view I want ONLY the active users listed in a CGridView. From the admin module they need to see ALL users. I have tried

if (Yii::app()->controller->module->id == 'admin')

but it comes back with an error of "trying to something from a non-object"

Can any body help, or should I duplicate code and make two models?

Using Yii 1.1.14

You should use something like

if (isset(Yii::app()->controller->module) && Yii::app()->controller->module->id == 'admin')

The reason being that the front-end apparently is not a module, so Yii::app()->controller->module does not return anything. You are, however, not determining whether an admin is looking at it, but whether someone is looking at it using the admin module, which in your case might be the same thing, but why not determine whether someone is an admin in a straight forward way?

You are correct “frontend” is just the main app. I can’t check if user is ‘admin’ because ‘admin’ could use both sides. I’m setting up the ability for the logged on user can change some of there profile information. An admin can change anyone’s profile from the ‘admin’ module AND there own in the main site profile area.

I will try your suggestion later, Thanks. I do believe I may have tried is_null() but I think I went down to ->id even in that :(