0

I am making this notification service which provides an api. Apis are actually static functions of one class 'Notifications'. One of the api functions is:getNotifications.

I need to access this class like this way:

mydomain/notification/getNotifications/$userId

I know I can make a module, or a controller, but I don't think this is the proper shape for a simple service component. Is there any other way around in yii?

Asgaroth
  • 4,274
  • 3
  • 20
  • 36
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56
  • I'd make a controller . . . alternatively, if you think that's a bad idea, you could create a static route to a special PHP file, but then why use Yii at all? – ernie Oct 17 '13 at 16:41
  • in terms of plugability, will it be good enough to make it in controller? so in the usage section, I ask people to insert my controller among theirs? special PHP file seems aweful! – Aladdin Mhemed Oct 17 '13 at 16:53
  • 1
    I'm not sure what you mean by plugability. I inferred that you meant you were building a web service . . . it sounds like you're talking about a module of some sort you want others to use? – ernie Oct 17 '13 at 21:57

1 Answers1

2

You need a controller, even if you are thinking about modules, the module would need a controller to handle HTTP Request, which is what they are for.

You can make your component "plugable" by providing just the component and let the users use it however they want, detaching it from the "url" concept if they want to, like using the Notifications object as part of a CLI.

You can also provide a controller with the component, whatever you desire, depending on what the component needs to do, to me it looks like you can shit it without the controller, and just let the user's handle that the best way it fits to them.

Asgaroth
  • 4,274
  • 3
  • 20
  • 36