Re: Route : defaut action for a controller

2006-09-28 Thread AD7six

This conversation seems much bigger than the problem being discussed :)

Why not
Define one route for /galleries/ (that uses the method index or
whatever you want to call it)
Define one route for /galleries/history/* (that uses the method
history)
Define one route for /galleries/* (that calls the method view, and
expects parameters).

But the url should be the last thing to consider, especially as most
people don´t bother to look at it :).

Anyway, just an idea,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-28 Thread [EMAIL PROTECTED]

xOrster: what a user want's to have a gallery named "list" ? what then?
I think it's not a good way to define the second url parameter as a
method parameter

I think the best way would be something like
http://host/galleries/gallery/foo

but I know it would be better your way, is just you are limiting your
users.

And if you want this functionallity anyway (you would need to make sure
a user doesn't name their galleries as your controller's methods) is
not that hard add routes for each of your methids manually... is not
that you are adding new methods each hour!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread x0rster

I took the blog example from the cakephp manual to explain what I want,
but i'm not developping a blog but a web gallery, for example :
I have 2 galleries : foo, and bar
I want to access them from http://host/galleries/foo and
http://host/galleries/bar
If someone try something else like
http://host/galleries/notexistinggallery
then my index function will render a page saying the gallery did not
exist.

And I want also to have for example : http://host/galleries/list to get
the list of existing galleries.

So if I have understood, the only way is to create a route for each
other funtions.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread Brian French




Why would you want a catch-all? What would you want to do if someone
hit http://localhost/blog/sumthin ?

However, with the way that AD7six explained it, it should create your
catch-all functionality.
The bad thing is that you may have to define a route for every method
in the blog controller to access them.

$Route->connect ('/blog/history/*,
array('controller'=>'Blog','action'=>'history'));
$Route->connect ('/blog/*',
array('controller'=>'Blog','action'=>'index'));

At least this is how i understand it. 
Side question: As far as i understand it, if you have a method with a
preceding "_" ( _someMethod(){} ), you shouldn't be able to access it
by going to http://localhost/blog/_someMethod right?
If you were to create a route to it, then would it that method be
accessable via the url? (Not saying i would do it as it doesnt seem
very cakey, just curious).

Brian French

x0rster wrote:

  Ok, thanks you AD7six
So I need to add a route for each other members functions in
BlogController. It's too bad that there is no way to define a route
functionning like a "catch-all" if the function does not exist.

Thanks for your help




  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---





Re: Route : defaut action for a controller

2006-09-27 Thread x0rster

Ok, thanks you AD7six
So I need to add a route for each other members functions in
BlogController. It's too bad that there is no way to define a route
functionning like a "catch-all" if the function does not exist.

Thanks for your help


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread Vanchuck

I don't know if this can be done automatically just using a single
route. If you want:
http://host/blog/test  => Blog->Index('test')
BUT
http://host/blog/history/2006 => Blog->History('2006')

Then one thing you could do is hand over the routing logic to your
BlogController's index function, by using the following route:

$Route->connect('/blog/*', array('controller'=>'Blog',
'action'=>'index'));

Then, in your index function check to see if the first parameter passed
is a defined action in the controller by using method_exists($this,
<>);, and if it does exist use call_user_method(); to
hand over execution to that action (you'll have to make sure you also
manually set which view to render by calling
$this->render('actionname') in each of your actions. The problem with
this though is it is a security issue since if someone enters
http://host/blog/redirect, since method_exists($this, 'redirect')
exists in AppController, it would execute that function. If you use
some action-based security (like the ACM plugin), then its
functionality is messed up as well.

Alternatively (and probably the easiest way, unless you're going to
have dozens of actions), like AD7 says, you can simply define routes
for all your OTHER actions above where you do the /blog/* catch-all
route, then you get the same desired effect with a lot less hacking.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread Schinki

Ok, I think I didn´t understand your problem properly, xOrster! ;o)
I didn´t know that you want all actions redirect to index, except
"history".

I think the answer by AD7six is right. I didn´t test it, but it sounds
correct.

Cheers.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread Schinki

Ok, I think I didn´t understand your problem properly, xOrster! ;o)
I didn´t know that you want all actions redirect to index, except
"history".

I think the answer by AD7six is right. I didn´t test it, but it sounds
correct.

Cheers.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-27 Thread AD7six

<< Google posting errors are a pain, the posts usually go through and I
apologise in advance if this is a duplicate post >>
Hi x0rster,

I hope I can add some clarity :)

> $Route->connect ('/blog/:action/*', array('controller'=>'Blog',
'action'=>'index'));

This route says that the second parameter in the url is named "action"
with a DEFAULT of index. As pointed out by  Schinki this route is
redundant as this is what cake does anyway.
So, using this route =>
/blog/ == blog controller index method
/blog/history/ = blog controller history method
/blog/test/ = blog controller test method

If you search around the group you will find a comment from Nate to the
effect of "consider routes as regex predicates". What does that mean?

If you define these routes in this order:
$Route->connect ('/blog/*', array('controller'=>'Blog',
'action'=>'index'));
$Route->connect ('/blog/history/*, array('controller'=>'Blog',
'action'=>'history'));

the History route is irrelavent, because the blog/* route captures
everything.

If you define these routes in this order:
$Route->connect ('/blog/history/*, array('controller'=>'Blog',
'action'=>'history'));
$Route->connect ('/blog/*', array('controller'=>'Blog',
'action'=>'index'));

IFF the url begins with /blog/history/ your history aAction will be
called and in all other (blog) urls the index will be run.

I did this in the past (although running 1.2), so I hope the
information is accurate, if not I´m sure someone will correct me ;).
There is another solution if this doesn´t work by overriding the way
errors are handled, but that is perhaps a bit too involved, so I want
go into unnecessary details.
Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread x0rster

Oups,

Sorry I've got some problems with google groups server


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread x0rster

I will try to explain more precisely :

I want that http://host/blog/test invoke index action of blog
controller with "test" as a parameter to index function if test is not
a member function of blog controller
And if test is a function of blog controller, I want that test function
is runned and not index...

Actually without a route I'm getting "Missing method in BlogController
[...] action test is not defined in controller BlogController" but I
want that test become a parameter of index method in BlogController.
With $Route->connect("/blog/*",
array("controller"=>"Blog","action"=>"index") everything is redirected
to index action as parameters, even if method test, for example, is
defined in BlogController...

Is this more clear ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread x0rster

I will try to explain more precisely :

I want that http://host/blog/test invoke index action of blog
controller with "test" as a parameter to index function if test is not
a member function of blog controller
And if test is a function of blog controller, I want that test function
is runned and not index...

Actually without a route I'm getting "Missing method in BlogController
[...] action test is not defined in controller BlogController" but I
want that test become a parameter of index method in BlogController.
With $Route->connect("/blog/*",
array("controller"=>"Blog","action"=>"index") everything is redirected
to index action as parameters, even if method test, for example, is
defined in BlogController...

Is this more clear ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread x0rster

I will try to explain more precisely :

I want that http://host/blog/test invoke index action of blog
controller with "test" as a parameter to index function if test is not
a member function of blog controller
And if test is a function of blog controller, I want that test function
is runned and not index...

Actually without a route I'm getting "Missing method in BlogController
[...] action test is not defined in controller BlogController" but I
want that test become a parameter of index method in BlogController.
With $Route->connect("/blog/*",
array("controller"=>"Blog","action"=>"index") everything is redirected
to index action as parameters, even if method test, for example, is
defined in BlogController...

Is this more clear ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread Schinki

Hi.
I think, you don´t need to rewrite your Router.
"index" is the default action, if no action is given.

url: www.example.com/blog/ -> controller: blog, action: index

Am i wrong or i can´t understand you?


Cheers.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Route : defaut action for a controller

2006-09-26 Thread [EMAIL PROTECTED]

Sounds like what youa re wanting is a

$Route->connect('/blog', array('controller'=>'Blog',
'action'=>'index'));

You cannot using the :action and then also explicitly define the
action.  And if you didn't then you are just reverting back to the
default behaviour.  So, sounds like you just want them when they hit
blog to be redirected to the blog index.  And that all other CakePHP
links should function normally.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---