Tuesday, July 27, 2010

Re: REST connect to component function?

Majna,

This is very helpful. I will have to re-read a few times, but very
helpful!

With such a RestController, it seems like I could then include the
component in AppController or other controllers for non-REST access.
My goal is to not duplicate simple functions like person and country
lookup/list.

Thanks,

Jim

On Jul 27, 12:13 pm, majna <majna...@gmail.com> wrote:
> You can't  route to component but you can crate proxy controller
> and use PHP's __call()  to re-route to component method .
> maybe like this:
>
> RestController:
> function rest($method) {
>     $this->{$method}();
>
> }
>
> public function __call($method, $arg) {
>     return call_user_func(array($this->Beer, $method));
>
> }
>
> RestComponent:
> public function test() {
>     debug($this->controller->params);
>
> }
>
> Url:  /rest/test/edit/23
> now you can use passed params in component,
> override controller's params like view, layout...
> and call controller->render
>
> On Jul 27, 6:33 pm, geste <jim.ho...@gmail.com> wrote:
>
>
>
> > I am trying to gather some common functions in a component I am
> > calling "Lookup".  This will house basic  functions like
> > "LookupUserLastFirst" (to produce lists of users sorted by last name
> > and first name).
>
> > Part of my purpose in doing this is to make some of these functions
> > available on a read-only basis to our CMS via REST.
>
> > I am looking at the 1.3 documentation for REST including custom REST
> > routing:
>
> >  http://book.cakephp.org/view/1240/Custom-REST-Routing
>
> > Is there a way to use custom routing to connect to functions in a
> > controller?  All of the examples seem to point to "controller/
> > action".  Do I need a stub controller that just includes the component
> > so I can do it that way, or is there a way to build a route like
> > "controller/component/function(action)" to call those directly?
>
> > Thanks,
>
> > Jim

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: