我有一个yii应用程序(APP1)和一个单独的yii应用软件,我想将多个行/表从APP1下载到APP2,完成一些操作,然后将它们发送回 APP1PP2目前,我有一个请求(使用 我不太确定如何最好地从这里开始?有人对如何处理这个问题有什么想法吗? 这为我提供了我需要的所有数据,现在我需要将这些数据放入APP2数据库中的临时表中,然后我可以在完成后修改发送回 **更新**这里的另一个问题是,APP1将在活动服务器上,而APP2将托管在WAMP服务器上。APP2需要从APP1获取数据(表/行),然后在工作完成时脱机。一旦作业完成(并且APP2有互联网连接),它将需要将数据传回APP1进行处理感谢您的帮助GET
),它为我提供了APP1中json
对象中所需的所有数据。public function actionDownload($id) {
// Check if id was submitted via GET
if(!isset($_GET['id']))
$this->_sendResponse(500, 'Error: Parameter <b>id</b> is missing' );
$model = AuditLines::model()->findAll(array("condition"=>'line_audit_id='.$_GET['id']));
if(is_null($model))
$this->_sendResponse(404, 'No Items found with id '.$_GET['id']);
else
$this->_sendResponse(200, CJSON::encode($model));
}
您可以通过创建一个Web服务来实现这一点
我将向您展示如何使用soap
在App1中
class WebServicesForUserController extends Controller
{
public function actions()
{
return array(
// 'services' will be used in app2 while making soap object
'services'=>array(
'class'=> 'CWebServiceAction',
)
);
}
/**
*@return mixed
*@soap
*/
public function sendData()
{
// do all your processing here and store data in a variable
$variable=array('my data');
// then just return the data in the json form
return json_encode($variable);
}
}
在APP2中,您可以调用此Web服务来获取类似的数据
class GetMyServiceController extends CController
{
public function actionMyData()
{
// create a soap object
$wsdl='http://path/to/your/app1/function/services';
$client=new SoapClient($wsdl);
$result=$client->sendData();
echo $result
}
}
有关更多详细信息,请点击此处
您可以在一个应用程序中打开多个数据库到不同数据库的连接
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=dbserver1;dbname=my1db',
...
),
'dbadvert' => array(
'connectionString' => 'mysql:host=adserver2;dbname=advertisingDB',
'username' => 'advertuser',
'password' => '***********',
...
'class' => 'CDbConnection' // DO NOT FORGET THIS!
),
来源:http://www.yiiframework.com/wiki/123/multiple-database-support-in-yii/#hh0
此外,如果两个应用程序都托管在同一服务器上,那么app1可以从另一个物理位置加载控制器/模型/助手,然后从受保护的路径中加载。