Welcome Guest, Not a member yet? Register   Sign In
Codeigniter + XML newbie
#1

[eluser]Ickes[/eluser]
Hello.

This is my first attempt to integrate XML into my CI projects. I am trying to receive an XML data feed from a website into my CI website.

Where do I place my php to receive the XML data feed?
Should I do something like www.MySite.com/data_controller - that doesn't seem right to me.
I don't believe I can do something like www.MySite.com/xml_gets_received_here.php as the CI framework would not allow such a thing?
Additionally, on this config, I don't have access outside the web root.

I am not receiving nor transmitting sensitive information but I want to code properly now so that the habit is developed. Can anyone help with this probably obvious question?

Thanks.
#2

[eluser]Cro_Crx[/eluser]
Quote:Where do I place my php to receive the XML data feed?

If it's going to be used on a single page then a controller would be the best place. If you plan to use it all over your projects or want to reuse the code in the future, maybe consider creating a helper/library, the documentation is in the user guide for this.


Quote:Should I do something like www.MySite.com/data_controller - that doesn’t seem right to me.

You should name your controllers something relevant. So assuming you put your XML code into a controller then for example let's say that controller is showing you user data, then you would name it www.MySite.com/user-data <=== dash or underscore.

If you put the code into a model then name it something appropritate such as "xml_interpreter" or something similar.

Quote:I am not receiving nor transmitting sensitive information but I want to code properly now so that the habit is developed. Can anyone help with this probably obvious question?

Yes.
#3

[eluser]Ickes[/eluser]
Thanks for the help so far. I've read more and think a re-phrasing may help.

How do I receive a simple XML feed from another web site?

I can process the XML just fine IF I could receive it. I currently have a controller (call it XML) and a function (call it receive). Before using CI, I received this simply by seeing if $_POST['xml_request'] was set.

So, the xml is directed to
www.mysite.com/XML/receive

Code:
function receive()
{
  if (isset($_POST["xmlData"]))
  {
  //process the xml
  //THIS NEVER HAPPENS
  }
  else
  {
  //don't process
  //THIS NEVER HAPPENS EITHER
  }
}

If someone can tell me what is wrong or even where to hunt, that would be great. Some thoughts that I have had that have not turned up successful.
1) The function needs a parameter such as function receive($xml_data) OR
2) Perhaps an XML-RPC server needs to be set up where the XML would be received by the XML-RPC server function and then passed to a processing function?
3) Something completely else that I have no idea about.

Any help would be great.

Thanks.
#4

[eluser]Ickes[/eluser]
Or maybe I could just use proper programming such as

Code:
$this->input->post('xml_data')

Yeah, that worked. Sorry for wasting anyone's time.
#5

[eluser]Ickes[/eluser]
Well, once again lost. Could someone help me start all over? Here's what's going on in the most basic simplicity..

XML file is being sent from a remote site to my site.
An XML example...
Code:
&lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?&gt;
<things>
  <thing>
    <name>Some Name</name>
    <stuff>Test</stuff>
  </thing>
</things>

My site is trying to receive the XML and then process it. But, for now, I'd be happy with my site even acknowledging that it received the XML.
Code:
class XML extends Controller
{
    function process()
    {
            echo "received";
        }
}

The idea behind this INCREDIBLY basic example is to have the external site send the XML to site.com/XML/process and have the process function return "received".

Instead, nothing is happening. Any ideas? I've thrown the kitchen sink at it. Might it have something to do with an .htaccess file or the removal of /index.php? Really, any ideas would be great.
#6

[eluser]Ben Edmunds[/eluser]
Well the first thing to try would be writing something to a database or log file when the method is called because the service that is calling your site might not be reading the data correctly or it might only expect certain results. So first you want to make sure your method is running.

Next you should check the documentation for the service that is calling your site and see what data it is expecting. Then make sure you are returning data it expects. Check your headers! Check your formatting! Not all sites/services are programmed to be very robust and some are extremely picky on what they expect to be returned.

Also, it might sound dumb but make sure you can get to it from a web browser, if you can't get to it, neither can the web service...
#7

[eluser]Ickes[/eluser]
Thanks Ben. No luck though...

Quote:Well the first thing to try would be writing something to a database or log file when the method is called because the service that is calling your site might not be reading the data correctly or it might only expect certain results. So first you want to make sure your method is running.

The method is not running. I think that is the main issue. But I believe it is an issue with accessing CodeIgniter, not the service itself. The service has worked fine with the same code on a non-CI site.

Quote:Next you should check the documentation for the service that is calling your site and see what data it is expecting. Then make sure you are returning data it expects. Check your headers! Check your formatting! Not all sites/services are programmed to be very robust and some are extremely picky on what they expect to be returned.

The service will show whatever is returned in its logs. Problem is it isn't returning anything.

Quote:Also, it might sound dumb but make sure you can get to it from a web browser, if you can’t get to it, neither can the web service…

From a web browser, everything is normal.

So I guess the question is - know any idea why CodeIgniter would prevent access to a method / function? Could this deal with the .htaccess removal of index.php?
#8

[eluser]Ben Edmunds[/eluser]
OK hmmm.

Do you have a URL that I can check out and some example code?




Theme © iAndrew 2016 - Forum software by © MyBB