See section 4.2 in the manual for an explanation of the argument-URL
convention in web2py (P. 113; http://www.web2py.com/examples/default/docs)
Note: If a controller function takes arguments, it is not exposed to views
(rather, just for server-side use); passing from view to controller is done
through request.args[], or request.vars. For example,
...
<td>{{=A(uname, _href=URL(r=request, f='edit_user',
args=[uname]))}}</td>
...
would be fetched as:
...
def edit_user():
uname = request.args[0]
...
You can see what request vars and args look like by having a look at
http://www.web2py.com/examples/simple_examples/hello6
I hope that helps.
Regards,
- Yarko
On Fri, Oct 2, 2009 at 9:21 AM, znafets <[email protected]> wrote:
>
> Hi,
>
> searching two days now, didn't get it yet.
> How do I pass an argument from a view to a controller function ?
>
> I create a view with a list of users like:
>
> user1 role location ....
> user2 role location ....
> ...
>
> the user fields are URLs pointing to a controller function called
> "edit_user"
>
> The function edit_user creates a new form which is to be populated
> with the values of the user that was selected from the user list.
>
> How can I pass e.g. "user2" to "edit_user" function or where can I
> retrieve it ?
> e.g.
>
> MODEL
> db.define_table('user',
> SQLField('name'),
> SQLField('role'),
> SQLField('location'))
>
> VIEW (list)
> {{extend 'layout.html'}}
>
> <h1>Users</h1>
>
> <table frame="box" rules="all">
> <colgroup width="200" span="5">
> <th><h2>user</h2></th>
> <th><h2>role</h2></th>
> <th><h2>location</h2></th>
>
> {{for item in message:}}
> {{(uname, urole, uloc) = item.split()}}
> <tr>
> <td>{{=A(uname, _href=URL(r=request, f='edit_user'))}}</td>
> <td>{{=urole}}</td>
> <td>{{=uloc}}</td>
> </tr>
> {{pass}}
> </table>
> <br />
>
> how can I pass "uname" to the controller function 'edit_user' or where
> can I acces the information ?
>
> I tried something like:
> <td>{{=A(uname, _href=URL(r=request, f='edit_user', args=
> [uname, urole, uloc]))}}</td>
>
> which doesn't work (invalid request), it screws the url with
> additional data so that the function edit_user will not be found.
>
> Any idea if this is possible ? I did not find any example in the
> documentation for such a case.
>
> best regards
> Stefan
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---