[Catalyst] One controller from other

linuxsupport lin.support at gmail.com
Sun Dec 5 13:23:18 GMT 2010


OK, may be you got it wrong or I am really doing bad.

There is a model called DB, now if I use below code in controller User

$c->model('DB::User')->all;

Is it not correct?

On Sun, Dec 5, 2010 at 12:51 PM, David Schmidt <davewood at gmx.at> wrote:

> On Sun, Dec 5, 2010 at 6:32 AM, linuxsupport <lin.support at gmail.com>
> wrote:
> > Yes, other controller has just logic it use a model to get user list fr=
om
> > database.
> > However, I forgot to pass $c context. it is working as following
> >
> > $c->controller('User')->users($c);
> >
> > Thanks
> > Aniruddh
> >
> > On Sun, Dec 5, 2010 at 1:25 AM, David Schmidt <davewood at gmx.at> wrote:
> >>
> >> On Sat, Dec 4, 2010 at 4:00 PM, linuxsupport <lin.support at gmail.com>
> >> wrote:
> >> > Hi,
> >> >
> >> > How can I access one controller from other?
> >> >
> >> > I have 2 controllers called Myapp::Controller::User and
> >> > Myapp::Controller::Admin
> >> >
> >> > In Myapp::Controller::User I have following method.
> >> >
> >> > sub user_list :Path Args:(0) {
> >> >    some function to display all the users.
> >> > }
> >> >
> >> > Myapp::Controller::Admin has following method
> >> >
> >> > sub users :Path Args(0) {
> >> >   Here I want to display all users by calling Myapp::Controller::User
> >> >   $c->controller('Myapp::Controller::User')->user_list is not working
> >> > }
> >> >
> >> > any suggestion?
> >> >
> >> > Thanks
> >> >
> >> > _______________________________________________
> >> > List: Catalyst at lists.scsys.co.uk
> >> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> >> > Searchable archive:
> >> > http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> >> > Dev site: http://dev.catalyst.perl.org/
> >> >
> >> >
> >>
> >> Don't abuse your Controller as a model.
> >> Controllers ideally only contain logic important for the GUI flow.
> >> Returning a list of users should be provided by a models method.
> >>
> >> david
> >>
> >> _______________________________________________
> >> List: Catalyst at lists.scsys.co.uk
> >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> >> Searchable archive:
> >> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> >> Dev site: http://dev.catalyst.perl.org/
> >
> >
> > _______________________________________________
> > List: Catalyst at lists.scsys.co.uk
> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> > Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> > Dev site: http://dev.catalyst.perl.org/
> >
> >
>
> It's still wrong to call a method on another controller to get a list of
> users.
> You should definitely read more about MVC.
> start here:
> http://search.cpan.org/~zarquon/Catalyst-Manual-5.8005/lib/Catalyst/Manua=
l/About.pod#The_MVC_pattern<http://search.cpan.org/%7Ezarquon/Catalyst-Manu=
al-5.8005/lib/Catalyst/Manual/About.pod#The_MVC_pattern>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101205/9466a=
1b2/attachment.htm


More information about the Catalyst mailing list