Php and web dispatcher

93 views
Skip to first unread message

Jimmy Delas

unread,
Apr 3, 2014, 3:34:44 PM4/3/14
to haxe...@googlegroups.com
Hey,

I'm trying to use the haxe web dispatcher but I'm experiencing some trouble.

So first, my host is under a folder called haxe.
Then, my project is under haxe/project.
The project is compiled under haxe/project/bin.

So basically, the index url is "haxe/project/bin/index.php"

To use the web dispatcher, I also use a .htaccess which hide index.php so my URL can look like "haxe/project/bin/dispatcher/args"

What I want to retrieve to use the web dispatcher is "/dispatcher/args"

Using Web.getUri() provides me "/project/bin/dispatcher/args". Not everybody in the project is having the same host tree so some people don't have any problems.

The only workaround I found to stay flexible to others is to use "untyped __var__('_SERVER', 'SCRIPT_NAME')" to cut the first part of getUri().

However, it seems so ugly that I really want to find an alternative.

So how to this properly ?
Message has been deleted

Jimmy Delas

unread,
Apr 3, 2014, 9:24:26 PM4/3/14
to haxe...@googlegroups.com
In case I wasn't clear enough.

Here is what I want to achieve in a smart and nice way

var src : String = untyped __var__('_SERVER', 'SCRIPT_NAME');
var url : String = StringTools.replace(Web.getURI(), src.substr(0, src.length - "/index.php".length), "");

which produce from an URL such as "haxe/testProject/bin/how/are/you" => "/how/are/you"

Jason O'Neil

unread,
Apr 4, 2014, 7:14:50 PM4/4/14
to haxe...@googlegroups.com
Hi Jimmy

In terms of the ugliness of fetching `$_SERVER['SCRIPT_NAME']`, there's probably not much better, though you could do something like this:

var serverVars:Map<String,String> = php.Lib.hashOfAssociativeArray(untyped __php__("$_SERVER"));

and then use the serverVars map to check for the "SCRIPT_NAME" header.  You can hide the ugliness behind a function if you don't want to look at it any more, which is what php.Web.getClientHeaders essentially does ;)

Once you have the server vars, you can use:

    var scriptName = serverVars.get( 'SCRIPT_NAME' );
    var projectPath = haxe.io.Path.directory( scriptName );
    var currentUri = Web.getURI().substr( projectPath.length );

Which should trim the project path from your given URI.

Hope that helps

Jason


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

tom rhodes

unread,
Apr 5, 2014, 2:47:49 AM4/5/14
to haxe...@googlegroups.com
ufront is a bit more elegant in handling this though right? as i remember it you can pass the root path when you start the application off, and I think it handles losing "whatever.n" or "whatever.php" itself when urls are rewritten.

Jimmy Delas

unread,
Apr 5, 2014, 9:26:06 AM4/5/14
to haxe...@googlegroups.com
I was thinking of hiding it under a function Jason.

I like your way of handling it too.

I'm not sure what you mean Tom ? The other way would be to manage this kind of "base url" into a configuration file. Is that what you're saying ?

Thanks dudes anyway :)

                                                                  

Jimmy Delas


You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
Reply all
Reply to author
Forward
0 new messages