Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-23-2007, 02:13 PM
Junior Member
 
Join Date: Oct 2007
Posts: 27
Default GET forms with the MVC

I have an application which uses GET forms for the purpose of providing links which one person can send to another. For example:

Code:
projects.php?action=list&team=Design&client=SomeClientName&status=All
I am in the process of migrating to ZF and have a working MVC application. If i submit the above form I end up with something similar to:

Code:
/projects/list/?team=Design&client=SomeClientName&status=All
Ideally I would end up at

HTML Code:
/projects/index/team/Design/client/SomeClientName/status/All
OR
Code:
/projects/index/Design/SomeClientName/All
Is there a particular method I have missed for this, or should I be submitting my forms to some kind of /bounceController which redirects to the neat URL ?

I wonder if a Controller Plugin can be written, to detect a GET request with variables, and perform the rewriting.

Last edited by Davidoff : 10-23-2007 at 02:28 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-24-2007, 10:25 PM
Member
 
Join Date: Jun 2007
Posts: 33
Default

Your third item, "Ideally I would end up at" is exactly how the ZF currently works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-25-2007, 10:11 AM
Junior Member
 
Join Date: Oct 2007
Posts: 27
Default

Indeed, the third url is what Zend Framework would process.

What I was trying to say is that if I submit a form, to /projects/list the URL will be

Code:
/projects/list/?team=Design&client=SomeClientName&status=All
I'm trying to find the best way to handle GET forms to finish at a clean URL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-25-2007, 10:20 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

Code:
/projects/list/team/Design/client/SomeClientName/status/All
Quote:
Originally Posted by Davidoff View Post
Indeed, the third url is what Zend Framework would process.

What I was trying to say is that if I submit a form, to /projects/list the URL will be

Code:
/projects/list/?team=Design&client=SomeClientName&status=All
I'm trying to find the best way to handle GET forms to finish at a clean URL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-26-2007, 05:03 PM
Junior Member
 
Join Date: Oct 2007
Posts: 27
Default

I don't understand your reply Elemental; you didn't actually say anything.

Has anyone dealt with this issue before? Is the only way to issue redirects to attractive URLs?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-27-2007, 05:25 AM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

Code:
/projects/list/?team=Design&client=SomeClientName&status=All
can be entered in the url as

Code:
/projects/list/team/Design/client/SomeClientName/status/All
Which will be routed to the default module, projectsController, listAction with the following params:

'team' => 'Design'
'client' => 'SomeClientName'
'status' => 'All'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-27-2007, 12:36 PM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

You would access the variables in the controller using parent::_getParam(variableName);
Thought I should add that incase it wasn't clear.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-28-2007, 02:36 AM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

Quote:
Originally Posted by Leif.Högberg View Post
You would access the variables in the controller using parent::_getParam(variableName);
Thought I should add that incase it wasn't clear.
More commonly you see this.
Code:
//gets one param with the key of 'foo'
$this->_request->getParam('foo');

//gets all params and returns an array
$this->_request->getParams();
The params are part of the request object. I would think that parent:: would point to the Zend_Controller_Action class that your controller is extending vs. the request object.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-30-2007, 03:13 PM
Junior Member
 
Join Date: Oct 2007
Posts: 27
Default

Perhaps I haven't explained the problem very well - if thats the case, my apologies.

When I submit a form, (and when anyone on any website in the universe submits a form), via the GET method, they are redirected to

action?query_string

Where action is the form action, and the query string is a product of the form fields.

A ZF MVC application has pretty URLs. The URLs I generate to link from page to page are indeed 'pretty' URLs of the MVC format.

The address of a page you're taken to after submitting a form ISNT.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-30-2007, 08:05 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

I guess I don't follow, I write my urls as described above, whether they are for a GET form action, POST form action, anchor link, or whatever.

/module/controller/action/var1/val1/var2/val2/

the only exception for me is when I create custom routes.

I haven't had a ? & or = in a url since I moved to rewrite capable frameworks.

Generally I disable to default submit action of a form anyway and use AJAX to handle the form submit actions, but even in that case my urls all get written out the same way.

I have on occasion put my variables in the request headers so they aren't displayed in the url at all, but I only do that for sensitive data. Since is doesn't prevent anyone from actually seeing, only adds an extra step or three, its just a way to not openly broadcast the information.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:23 PM.