user1033199
user1033199

Reputation: 19

How to make a simple webservice application in yii?

I want to create a an webservice application in yii.As i am a new in yii so can someone suggest how can i do it.If i want to show google news in my application through webservice how can i do that?

Upvotes: 0

Views: 2010

Answers (1)

Asgaroth
Asgaroth

Reputation: 4334

If you are looking for a SOAP Web Service:

First add the Web Service Action to the controller you want to provide the service:

public function actions()
{
    return array(
        'api'=>array(
            'class'=>'CWebServiceAction',
        ),
    );
}

Then you need to mark the functions in the controller that you wish to become services, with a custom PHPDoc @soap, and also define all of the params and return types of your service in the PHPDoc, so that Yii can generate the correct WDSL:

/**
 * @param string the module
 * @return string the version
 * @soap
 */
public function getVersion($module)
{
    //...find the corresponding version
    return $version; // ie: v0.1.3
}

Source : Special Topics: Web Service

If you are looking for a REST service. then its a little more involved, as Yii doesn't have a built-in helper as it does for SOAP, but jwerner wrote a detailed wiki on how to create a REST Api with Yii

Upvotes: 2

Related Questions