2008年12月19日星期五

Re: [fw-mvc] Another routing question

Matthew;

Nevermind, I think it finally clicked. For anyone looking later, here
what I did:

config.ini (relevant data):
[routes]
routes.Admin-Reportbuilder.route = "admin/reportbuilder/:action"
routes.Admin-Reportbuilder.defaults.module = admin
routes.Admin-Reportbuilder.defaults.controller = reportbuilder

routes.Admin-Reportbuilder-action-obj_id.route =
"admin/reportbuilder/:action/:obj_id"
routes.Admin-Reportbuilder-action-obj_id.defaults.module = admin
routes.Admin-Reportbuilder-action-obj_id.defaults.controller = reportbuilder

(zapp is the baseurl, 'ssr' is an alias for a local dev server)

On http://ssr/zapp/admin/reportbuilder/

echo $this->url( array( 'action' => 'report', 'obj_id' =>
$report['hobj_id'] ), 'Admin-Reportbuilder-action-obj_id' );
// http://ssr/zapp/admin/reportbuilder/report/1NW9vZEk

echo $this->url( array( 'action' => 'delete', 'obj_id' =>
$report['hobj_id'] ), 'Admin-Reportbuilder-action-obj_id' );
// http://ssr/zapp/admin/reportbuilder/delete/1NW9vZEk

---------

On http://ssr/zapp/admin/reportbuilder/report/1NW9vZEk

echo $this->url(array('action'=>'save'),'Admin-Reportbuilder');
// /zapp/admin/reportbuilder/save
---------

So, my expectations were right but my config.ini setup was off.
Thanks for your help; your response with the default stuff set me down
the right path.

Hans

On Fri, Dec 19, 2008 at 10:59 AM, Hans Anderson <windsurf17@gmail.com> wrote:
>> The URL you're trying to build is targetting a different route -- in
>> this case, the "default" route. So, simply add a second parameter to
>> your url() call:
>>
>> <?php echo $this->url(array('action'=>'copy'), 'default'); ?>
>>
>> --
>> Matthew Weier O'Phinney
>
> Matthew;
>
> That worked, thanks. Is there a way it can detect the mod/ctr and I
> can just overwrite the action? This is the behavior I expected,
> though not for any particular reason other than terseness:
>
> given page: /admin/reportbuilder/save
>
> 1. echo $this->url();
> // basically the current URL, such as /admin/reportbuilder/save
> // similar to $PHP_SELF in standard PHP
>
> 2. echo $this->ur(array('action'=>'copy'));
> // existing mod/ctr, overwrite action to 'copy': /admin/reportbuilder/copy
> // also defaults to $Name='default'
>
> Just trying to get a better understanding; I'm going to be using
> routing extensively in the near future.
>
> Thanks,
> Hans
>

--
Hans Anderson
+ growth is sparse on the tops of mountains +
http://thechurchengine.org/
http://hansanderson.com/
http://worldwidewedgy.com/
http://devilsradar.com/

没有评论: