>>I'm not sure you'd really want $c->dbh anyway, since that's doesn't >>sound like you would be encapsulating the Model very well, and sounds >>like you'd have SQL in your controller code?
This was what I thought and am trying to avoid, I am doing my best to keep concern with SQL trot he Model and any action/method that requires data to use the Model and have the business logic kept in the Model, so that only actions->routes and the additional application helper methods are in the controller. I have read and seen frameworks such as Mojolicious encourage a shrinkage of the Model and move alot of functionality to the Controller, so there is a paradigm which seems to imply it is ok to do more stuff in the Controller, but I am leaning towards having the main code in the Model and then bolting it together via the Controller. So for example the authentication for the user is in the Controller but it simply utilises the Model EG. sub AuthenticateUser { my ( $self, $c ) = @_; $c->session; if(!$c->model('Members')->LogCheck($c)){ $c->forward('/login/login'); } } Dunno, this is all new to me and I'm refactoring as I go, so I doubt I'll get it right first time! Does anyone? ________________________________________ From: Rob Brown [r...@intelcompute.com] Sent: 29 October 2012 19:39 To: catalyst@lists.scsys.co.uk Subject: Re: [Catalyst] Why is $c undefined? Just a small FYI more than anything, which might help fill in a few gaps... $c->dbh would need you to modify MyApp.pm, this is useful at times for creating little helper methods that you want accessible via $c, or to override existing $c methods. The session plugin does this too, that's why $c->sessionid is available, etc. or $c->check_user_roles() when using the Authorization::Roles plugin. I'm not sure you'd really want $c->dbh anyway, since that's doesn't sound like you would be encapsulating the Model very well, and sounds like you'd have SQL in your controller code? On 10/29/2012 07:28 PM, Craig Chant wrote: > Cool, thanks. > > Reading the tutorial I got the impression $c was always passed. > > Thanks for clearing that up, which is why I guess $c->dbh doesn't exist. > > hmm, much for me to get my head round for sure! > > Regards, > > Craig. > > ________________________________________ > From: Rob Brown [r...@intelcompute.com] > Sent: 29 October 2012 19:11 > To: catalyst@lists.scsys.co.uk > Subject: Re: [Catalyst] Why is $c undefined? > > There's no black-magic going on, so your AuthenticateUser() sub never > "magically" gets $c. > > In short, you'll only get $c when using the method attributes, such as > :Private, :Chained, etc. > > > > > On 10/29/2012 07:07 PM, Craig Chant wrote: >> Hi, >> >> I seem to be unable to work out why $c is never automatically passed to >> any of my models or methods? >> >> I have in root.pm >> >> # always runs first! >> >> sub begin :Private { >> >> my ( $self, $c ) = @_; >> >> # Authenticate >> >> $self->AuthenticateUser(); >> >> return 1; >> >> } >> >> I then have... >> >> sub AuthenticateUser { >> >> my ( $self, $c ) = @_; >> >> $c->session; >> >> if(!$c->model('Members')->LogCheck($c)){ >> >> $c->uri_for_action('/login/login'); >> >> } >> >> } >> >> However, $c is undefined and errors, it only works if I pass it $c from >> 'begin'.. >> >> $self->AuthenticateUser($c); >> >> I was under the impression that $c was the context (Catalyst) default >> variable and was always passed to every method / subroutine. >> >> is this not the case? >> >> Thanks, >> >> Craig . >> >> This Email and any attachments contain confidential information and is >> intended solely for the individual to whom it is addressed. If this >> Email has been misdirected, please notify the author as soon as >> possible. If you are not the intended recipient you must not disclose, >> distribute, copy, print or rely on any of the information contained, and >> all copies must be deleted immediately. Whilst we take reasonable steps >> to try to identify any software viruses, any attachments to this e-mail >> may nevertheless contain viruses, which our anti-virus software has >> failed to identify. You should therefore carry out your own anti-virus >> checks before opening any documents. HomeLoan Partnership will not >> accept any liability for damage caused by computer viruses emanating >> from any attachment or other document supplied with this e-mail. >> HomeLoan Partnership reserves the right to monitor and archive all >> e-mail communications through its network. No representative or employee >> of HomeLoan Partnership has the authority to enter into any contract on >> behalf of HomeLoan Partnership by email. HomeLoan Partnership is a >> trading name of H L Partnership Limited, registered in England and Wales >> with Registration Number 5011722. Registered office: 26-34 Old Street, >> London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by >> the Financial Services Authority. >> >> >> >> _______________________________________________ >> List: Catalyst@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/ > > -- > IntelCompute > Web Design& Online Marketing Experts > > http://www.intelcompute.com > > _______________________________________________ > List: Catalyst@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/ > This Email and any attachments contain confidential information and is > intended solely for the individual to whom it is addressed. If this Email has > been misdirected, please notify the author as soon as possible. If you are > not the intended recipient you must not disclose, distribute, copy, print or > rely on any of the information contained, and all copies must be deleted > immediately. Whilst we take reasonable steps to try to identify any software > viruses, any attachments to this e-mail may nevertheless contain viruses, > which our anti-virus software has failed to identify. You should therefore > carry out your own anti-virus checks before opening any documents. HomeLoan > Partnership will not accept any liability for damage caused by computer > viruses emanating from any attachment or other document supplied with this > e-mail. HomeLoan Partnership reserves the right to monitor and archive all > e-mail communications through its network. No representative or employee of > HomeLoan Partn ership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by the Financial Services Authority. > > _______________________________________________ > List: Catalyst@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/ -- IntelCompute Web Design & Online Marketing Experts http://www.intelcompute.com _______________________________________________ List: Catalyst@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/ This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by the Financial Services Authority. _______________________________________________ List: Catalyst@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/