0

I am developing a API with CodeIgniter Framework.

Scenario -

  1. My application will call my API with http://myapi.com/controler?parA=valA&parB=valB
  2. My controller will _GET the request and process it.
  3. Controller will call a view with $this->load->view('response',$data, true).

My View File -

Response.php

<response>
    <status>
        200
    </status>
    <mode>
        VisaCreditCard
    </mode>
    <options>
        <option name="Transfer" url="http://myapi.com/controller/transfer?id=8230&reason=illness" />
        <option name="Cancel" url="http://myapi.com/controller/cancel?id=3934"/>
        <option name="New Booking" url="http://myapi.com/controller/book_new" />
    </options>
</response>

Please note that the tag names are the same as I am using in my application although the values inside are vague. This is because I want you to notice the <options> and <option/>.

Problem

Now the problem is when I call my API, CI would do all its jobs and then give out this view where all i get on screen is

200 VisaCreditCard

When I check to see the Source Code of the page I get exactly what I want i.e the text that I have in my respons.php file Expectation I want the source code I got in my output to be on the visible to when I call that url.


Server Information

  • Ubuntu 13.04

  • Apache2

  • PHP 5

  • Codeigniter 2.1.3 (Rewrite PHP Short Tags - FALSE & .htaccess to omit index.php)


1
  • if your problem is resolved. consider accepting best answer. Commented Nov 15, 2016 at 14:15

1 Answer 1

0

After almost 7 hours of head-banging search, experiment and sufferings came the light.


I did two things and it was solved.

  1. Set on header that declared Content-Type:text/xml.
  2. Omit the third parameter $this->load->view('response',$data).

Now my code is :

<?php header ("Content-Type:text/xml"); ?>

<response>
    <status>
        200
    </status>
    <mode>
        VisaCreditCard
    </mode>
    <options>
        <option name="Transfer" url="http://myapi.com/controller/transfer?id=8230&reason=illness" />
        <option name="Cancel" url="http://myapi.com/controller/cancel?id=3934"/>
        <option name="New Booking" url="http://myapi.com/controller/book_new" />
    </options>
</response>

And, don't forget to convert the & into &amp; or you will dive into errors again.

Sign up to request clarification or add additional context in comments.

2 Comments

I linked you a potential duplicate. I guess this will be useful for you if you're using Codeigniter. I found it by using your questions title as search terms.
@hakre Thanks to notify. I had already removed the <pre> </pre> tags but didn't edit my answer here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.