Welcome Guest, Not a member yet? Register   Sign In
using both uri segments and query strings in 1 app
#1

[eluser]skibum001[/eluser]
I am building a facebook app that has some of the functionality of my web app. As such, I want to re-use all my models and a number of views in the facebook version.

On my web app, I am using CI's lovely uri segs but as the facebook app will use a fair bit of JS, I need to use their iframes which meaning lots of facebook style query strings getting appended to the URI.

So my question is, how do I use both?

I have different controllers for my web app and facebook and tried using $this->config->set_item but this didn't work (I am guessing because CI determines uri types before getting to my contoller).

Next I tried to hack index.php and codeigniter.php but without luck. I created a new /facebook/ dir which had index.php, codeigniter.php, common.php and config.php and which changed the basepath and apppath to these locations but left the basepath and apppath to everything else the same. When I try mysite.com/facebook/index.php all I get is a blank screen (previously I got error messages until I fixed the errors). mysite.com/facebook/wrongurl loads my custom 404 page perfectly.

How do I make this work? I only want query strings to work in the /facebook/ directory.

Thanks for your help.
#2

[eluser]re5et[/eluser]
I ran into the same problem. I have found a solution, however it does require editing a core file. I traced the problem back to system/libraries/URI.php, the problem is that if you use a query string, they assume you have enabled query strings, even if you haven't. Find the following:

Code:
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
            {
                $this->uri_string = key($_GET);
                return;
            }

and change it to:

Code:
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
            {
                if($this->config->item('enable_query_strings'))
                                {
                    $this->uri_string = key($_GET);
                    return;
                }
            }
#3

[eluser]skibum001[/eluser]
Thanks for the suggestion. I'll try it out and let you know!
#4

[eluser]skibum001[/eluser]
Re5et, you rock Springfield! That fix worked perfectly.

For anyone else who has lost much sleep and hair over trying to integrate facebook iframes and CI, here is a little summary.

In my facebook setup, I have selected FBML and a callback url to my facebook controller.
Leave the uri_protocol set to Auto in CI config
In my facebook controller constructor, I enable query strings, change my base_url and allow extra uri chars eg

Code:
$this->config->set_item('enable_query_strings', 'TRUE');

Then I am free to use FBML in my views and if I need lots of JS, I embed and iframe

Code:
<fb:iframe src='callbackurl/controller/method/' width='500' height='300' scrolling='no' frameborder=0 />

So, I still get to use all my existing classes and models. Happy days!
#5

[eluser]Colin Williams[/eluser]
I wrote a facebook app in CI awhile back. All I did was set enable query strings to true and that did the trick. No fuss about it.
#6

[eluser]skibum001[/eluser]
A facebook app with CI is pretty easy. The difficulty was trying integrate a site built with the CI framework (and not using query strings) with a facebook app using iframes (requiring query strings but not impacting on the www site)
#7

[eluser]narkaT[/eluser]
[quote author="skibum001" date="1225635319"]So my question is, how do I use both? [/quote]

the easiest solution I know:

change the following config variables in APP/config/config.php:
Code:
$config['uri_protocol']    = "PATH_INFO";

$config['enable_query_strings'] = true;

doing so will allow you to use urls like
/controller/method?value=1&foo=bar
#8

[eluser]re5et[/eluser]
[quote author="narkaT" date="1226430010"][quote author="skibum001" date="1225635319"]So my question is, how do I use both? [/quote]

the easiest solution I know:

change the following config variables in APP/config/config.php:
Code:
$config['uri_protocol']    = "PATH_INFO";

$config['enable_query_strings'] = true;

doing so will allow you to use urls like
/controller/method?value=1&foo=bar[/quote]

this is much better than my solution :lol:
#9

[eluser]taewoo[/eluser]
[quote author="narkaT" date="1226430010"][quote author="skibum001" date="1225635319"]So my question is, how do I use both? [/quote]

the easiest solution I know:

change the following config variables in APP/config/config.php:
Code:
$config['uri_protocol']    = "PATH_INFO";

$config['enable_query_strings'] = true;

doing so will allow you to use urls like
/controller/method?value=1&foo=bar[/quote]

narkaT: can you post your .htaccess? I'm trying to do this with "index.php?q=" removed from the URI string.
#10

[eluser]narkaT[/eluser]
I used the .htaccess from the wiki, worked fine for me Wink




Theme © iAndrew 2016 - Forum software by © MyBB