Jump to content


Photo

URIs (modified title: & The Zend Framework)


  • Please log in to reply
11 replies to this topic

#1 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 07:54 AM

Just wondering, what do you, if you use a standard convention use for format when passing variables though get, transformed by mod_rewrite?

I'm using a single $_GET index called 'route', wich can be used for all controller classes.... It's formatting of this string that I'm wondering about...

I now just use this style:

http://somesite.com/...parametervalue1 etc..

But I'm thinking something more along the lines of:

?route=controllerclassname/controllermethodname/[parameterkey1:parametervalue1]/[parameterkey2:parametervalue2]


Rewritten to:
http://somesite.com/...arametervalue2/

While still having the keys available in $_GET..

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 09:14 AM

On the other hand, I might as well use regular request uri, (rewritten when requested of course) because this way I'm exposing my navigational variables in the source just as obviously.

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 September 2006 - 11:52 AM

either use the rewrite rules to do it for you, or you can follow suit from the likes of Zend Framework's default Router object, which I'm hazarding a guess you are already doing?

<?php

$request = substr($_SERVER['REQUEST_URI'], 1);

if (strrpos($request, '/') === strlen($request) -1) $request = substr($request, 0, -1);

$request = explode('/', $request);
$vars = array();
for($i = 0, $c = count($request); $i < $c; $i++)
{
    $vars[$request[$i++]] = $request[$i];
}

var_dump($vars);

?>


#4 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 12:05 PM

Currently, I'm using this:

<?php
// Analyze route
$routeArr = explode('/',self::getRoute());
//Route accepted format: controller/method/parameterIndexName/parameterIndexValue/etc,etc
$className = array_shift($routeArr).'_Controller';
$methodName = array_shift($routeArr);
if($methodName === null){
	$methodName = 'index';
}
//Assemble parameter array:
$parameterArray = array_compose($routeArr,true);
?>

array_compose being an udf composing an associative array from a numeric one.
all getRoute basicly does is a simple explode.

The problem I have with this, is that it causes long URIs.

I think I'm just going to abandon the whole 'passing associative array' concept, since the order of elements is already under constraints for determening the controller and action (method).

#5 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 September 2006 - 01:08 PM

Depends how much data you need to pass via uri, if they are 'too long' perhaps you need to seek other methods of transfer.

also, on side note, my snippet creates a pseudo $_GET array:

http://www.example.com/foo/bar/boo/far

will create an array:
array(2) {
  ["foo"]=>
  string(3) "bar"
  ["boo"]=>
  string(3) "far"
}


#6 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 01:23 PM

Mine does the same, except that it uses the first value as controller, the second as method and parses what's left into an associative array for the parameter. Plus it supports setting default values for keys without values.

Example:

article/read/id/1/title/blah-blahblah/edit

Action: Article_Controller::read(array('id'=>'1','title'=>'blah-blahblah','edit'=>true));


#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 September 2006 - 01:54 PM

Identical to ZF's.

#8 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 02:42 PM

Identical to ZF's.


Then that is absolutely an utter and complete coincidence. I've never laid eyes on a single line of ZF.

I guess I'm just that good  :P (joking of course).

I take a look at it now though.  :)

#9 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 September 2006 - 03:03 PM

It's a very nice framework (preference plays a big part in any/all frameword decisions.) Not complete yet of course, and I anticipate there will be a price when it is finally released.

#10 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 04:01 PM

It's a very nice framework (preference plays a big part in any/all frameword decisions.) Not complete yet of course, and I anticipate there will be a price when it is finally released.


Luckily I wasn't intending on buying it, nor using it at all for that matter (ya'll know there's a difference  :-X).

I was just planning on borrowing some idea's.

:-X

#11 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 15 September 2006 - 05:15 PM

I'm not so sure Zend is going to ask anything for it.

This collection of ├╝bergeeks have volunteerd. So it's not likely to become a commercial product.

I'm thinking they'll GPL it, hoping this framework will become very popular, php5 piggyback riding off it's popularity to finally gain dominance over php4.

Edit:
Ok, not GPL but free none the less:

http://framework.zen...d-framework-1.0
http://framework.zen...license/new-bsd

Does it say anywhere I can't copy and modify parts of it?  ::)

Probably not, I won't bother reading any of it then.

Kidding, mods please don't kill me...:P

It would seem class name/location conventions and uri processing aren't the only things my custom framework in devleopment has in common with ZF. The caching systems are also very similar. Except mine supports chunked caching, a feature I couldn't spot in ZF, and ZF's caching engine has memcache support when available.

Also I noticed some logic where objects were being serialized for caching? What is that about? I'ts not output caching, I wonder in what situations that could be usefull..

I'm not really familiar with memcache, does it also allow for managing output caching in memory, or is it purely a resultset caching thing?

#12 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 18 September 2006 - 08:59 AM

I don't know, I've not used it nor looked into it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users