Yii Framework Forum: Web Service Question - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Web Service Question Rate Topic: -----

#1 User is offline   alexb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 04-May 10

Posted 04 May 2010 - 09:06 AM

Hi all,

I'm fairly new to the Yii framework, but i must say it's working out pretty well for me so far ;-)

I do have a specific situation I'm having trouble with...

I've extended the CDataProvider class for the sole purpose of changing the way my fetchData() function behaves (everything else is pretty much similar to the definition of the CActiveDataProvider class). Inside fetchData(), instead of the usual:

return CActiveRecord::model($this->modelClass)->findAll($criteria);


...I'm calling a web service to get my data, in the following way:

$this->soapClient->getData($this->modelClass);


Here's the code for getData inside my ServiceController class:

	/**
	 * @param string the model
	 * @return array the data
	 * @soap
	 */
	public function getData($pModel)
	{
		$query = "SELECT * FROM {{" . $pModel . "}}";
		$command=Yii::app()->db->createCommand($query);
		return $command->query()->readAll();
        }


So far so good, but the problem begins as soon as I'm trying to pass additional arguments for my query criteria (so I can get sorting, pagination enabled, etc). If I change my function to:

	/**
	 * @param string the model
	 * @param CDbCriteria the criteria
	 * @return array the data
	 * @soap
	 */
	public function getData($pModel, $pCriteria)
	{
		$query = "SELECT * FROM {{" . $pModel . "}}";
		
		if (!empty($pCriteria->order))
		{
			$query .= " ORDER BY " . $pCriteria->order . "";
		}
		
		$query .= " LIMIT " . $pCriteria->limit . " OFFSET " . $pCriteria->offset . "";
		$command=Yii::app()->db->createCommand($query);
		return $command->query()->readAll();
	}


...I get the following error:

Error 500
looks like we got no XML document


I realized that since I'm passing an object as one of my arguments, that it could be the reason for this, but I even tried passing my criteria parameters separately (like $pCriteria->order, $pCriteria->limit, $pCriteria->offset), and i still get the same error message. What could be causing this...

Thanks in advance
0

#2 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 04 May 2010 - 12:46 PM

View Postalexb, on 04 May 2010 - 09:06 AM, said:

...
So far so good, but the problem begins as soon as I'm trying to pass additional arguments for my query criteria (so I can get sorting, pagination enabled, etc). If I change my function to:

	/**
	 * @param string the model
	 * @param CDbCriteria the criteria
	 * @return array the data
	 * @soap
	 */
	public function getData($pModel, $pCriteria)
	{
		$query = "SELECT * FROM {{" . $pModel . "}}";
		
		if (!empty($pCriteria->order))
		{
			$query .= " ORDER BY " . $pCriteria->order . "";
		}
		
		$query .= " LIMIT " . $pCriteria->limit . " OFFSET " . $pCriteria->offset . "";
		$command=Yii::app()->db->createCommand($query);
		return $command->query()->readAll();
	}


...I get the following error:

Error 500
looks like we got no XML document


I realized that since I'm passing an object as one of my arguments, that it could be the reason for this, but I even tried passing my criteria parameters separately (like $pCriteria->order, $pCriteria->limit, $pCriteria->offset), and i still get the same error message. What could be causing this...

Thanks in advance


Regarding the "no XML document" error, check for syntax errors and correct class names (e.g. I experienced this message using a bad model class name). Do you get the WSDL if navigating your browser to the web service (controller/your_webservice_action)?

For passing a criteria object I think you may want to inherit (and use) your own DbCriteria class and add the following declarations to it
  /**
   * @var string
   * @soap
   */
  public $order;

  /**
   * @var integer
   * @soap
   */
  public $limit;

  /**
   * @var integer
   * @soap
   */
  public $offset;

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   alexb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 04-May 10

Posted 06 May 2010 - 02:26 PM

View Posttri, on 04 May 2010 - 12:46 PM, said:

Regarding the "no XML document" error, check for syntax errors and correct class names (e.g. I experienced this message using a bad model class name). Do you get the WSDL if navigating your browser to the web service (controller/your_webservice_action)?

For passing a criteria object I think you may want to inherit (and use) your own DbCriteria class and add the following declarations to it
  /**
   * @var string
   * @soap
   */
  public $order;

  /**
   * @var integer
   * @soap
   */
  public $limit;

  /**
   * @var integer
   * @soap
   */
  public $offset;

/Tommy


thanks for you help Tommy. I finally got it to work. Also (and this might be interesting to others who are using web services), it helps to disable the wsdl cache (set soap.wsdl_cache_enabled=0). I noticed that with cache enabled, it would complain about newly added soap functions, claiming that 'Function *** is not a valid method of this service'...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users