External Xml File

Hello, where can i place my external xml files in the project? I need to send request to xml files to get file contents from any controllers.

Hi,

You can place it where you want. It should just be readable by the webserver owner.

IF place the xml file under \protected\components, How should I read or access the xml file ?

you can use like this to access the file:

hope this is what you are loooking for


Yii::app()->baseUrl.'/protected/components/somefile.xml'

if you want to work with xml files this might be helpful:

to work with it…you can use something like this:







public function xyzRequest()


{


// Initialize the cURL session


//ob_start();




$this->curl = curl_init();


//$file = Yii::getPathOfAlias('webroot.assets').'/somefile.xml';




//$fp = fopen("$file", "w");





curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);


curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookie);//$this->cookie(it is storing the session value and for every time we are performing authenticaiton before we process with our new request) is value is $this->cookie = Yii::getPathOfAlias('webroot.assets').'/cookie.txt';


curl_setopt($this->curl, CURLOPT_URL, 'http://remoteurl.website.com/xyz/');


//curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);




//curl_setopt($this->curl, CURLOPT_FILE, $fp);




$result = curl_exec($this->curl);


curl_close($this->curl);


//print $result;


//$out = ob_get_contents();


var_dump($result);






Just as a matter of convention, I always find it to be more logical and better organizationally for my apps/web sites that use external data files to have a separate folder in the data directory called ‘xml’ (or ‘JSON’, or whatever).

Just a suggestion.