Jump to content

URIs (modified title: & The Zend Framework)


448191

Recommended Posts

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/controllerclassname/controllermethodname/parameterkey1/parametervalue1 etc..

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

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

Rewritten to:
http://somesite.com/controllerclassname/controllermethodname/parametervalue1/parametervalue2/

While still having the keys available in $_GET..
Link to comment
Share on other sites

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?

[code]<?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);

?>[/code]
Link to comment
Share on other sites

Currently, I'm using this:

[code]<?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);
?>[/code]

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).
Link to comment
Share on other sites

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:

[code]http://www.example.com/foo/bar/boo/far[/code]

will create an array:
[code]array(2) {
  ["foo"]=>
  string(3) "bar"
  ["boo"]=>
  string(3) "far"
}[/code]
Link to comment
Share on other sites

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));
Link to comment
Share on other sites

[quote author=Jenk link=topic=108144.msg434884#msg434884 date=1158328497]
Identical to ZF's.
[/quote]

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.  :)
Link to comment
Share on other sites

[quote author=Jenk link=topic=108144.msg434927#msg434927 date=1158332636]
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.
[/quote]

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
Link to comment
Share on other sites

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

This [url=http://framework.zend.com/contributors]collection of übergeeks[/url] 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.zend.com/license/zend-framework-1.0
http://framework.zend.com/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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.