I can't return an array of object with a webservice

I’m testing the web services feature of Yii and I can’t correctly return an array of objects or consume it using a web service.

Using the blog demo that comes with Yii I modify the PostController.php and Post.php files with the code in the webservice special topic of the Yii’s guide. This code is:


class PostController extends CController

{

public function actions()

    {

        return array(

            'service'=>array(

                'class'=>'CWebServiceAction',

                'classMap'=>array(

                    'Post'=>'Post',  // or simply 'Post'

                ),

            ),

        );

    }




    /**

     * @return Post[] a list of posts

     * @soap

     */

    public function getPosts()

    {

        return Post::model()->findAll();

    }

}

 

class Post extends CActiveRecord

{

    /**

     * @var integer post ID

     * @soap

     */

    public $id;

    /**

     * @var string post title

     * @soap

     */

    public $title;

 

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }

}

When I try to consume this my httpd service loads the memory of the computer and finally the process fails and stop. This is the code where I try to use the array of posts.


$client=new SoapClient('webserviceaddress');

$posts = $client->getPosts();

.

I don’t know if the problem is when returning the data or reading it.

Welcome to the forum!

Your code seems OK (if you use access control, add the ‘service’ action). Perhaps try a different name for the service.

I recommend you start with a method returning just one object. (You may have to disable wsdl caching). Dump (e.g. print_r) the returned data and check for error mesages.

Check the web server log for clues. Server side, enable Yii file logging (web logging must not be active).

/Tommy

Sorry for the delay on my answer. To solve my problem I just moved the @soap tagged functions to a new Controller based class and that’s it. I still don’t know why it did’nt worked before.