I want to thro a validation error if a user is not logged in. This is because i have a mechanism to display model validation errors in the view and dont want to add controller level error displaying handler. Please suggest that how can i proceed to check the session in the model. I dont think that it is possible to access Session component in the model. Is It?
But I think the general consensus is that you should not.
With that said, please remember that with MVC we are still dealing with classes, member variables and methods here.
There is nothing stopping you from assigning a Model member variable in your controller, based on the session, then using that in your Model code as needed.
On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer <novice.prog...@gmail.com> wrote:
> I want to thro a validation error if a user is not logged in. This is > because i have a mechanism to display model validation errors in the view > and dont want to add controller level error displaying handler. Please > suggest that how can i proceed to check the session in the model. I dont > think that it is possible to access Session component in the model. Is It?
> But I think the general consensus is that you should not.
> With that said, please remember that with MVC we are still dealing with
> classes, member variables and methods here.
> There is nothing stopping you from assigning a Model member variable in your
> controller, based on the session, then using that in your Model code as
> needed.
> On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer <novice.prog...@gmail.com>
> wrote:
> > Hello All,
> > I want to thro a validation error if a user is not logged in. This is
> > because i have a mechanism to display model validation errors in the view
> > and dont want to add controller level error displaying handler. Please
> > suggest that how can i proceed to check the session in the model. I dont
> > think that it is possible to access Session component in the model. Is It?
What do you suggest then? Should i assign the value of error in controller to the array that comes out from validation? Doesn't it break MVC paridigm. I mean model is supposed to give us data and we are still not satisifed with what it has outputted to us?
On Thu, Mar 6, 2008 at 11:39 PM, Baz <bazil...@gmail.com> wrote: > Anything is possible...
> But I think the general consensus is that you should not.
> With that said, please remember that with MVC we are still dealing with > classes, member variables and methods here.
> There is nothing stopping you from assigning a Model member variable in > your controller, based on the session, then using that in your Model code as > needed.
> On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer < > novice.prog...@gmail.com> wrote:
> > Hello All,
> > I want to thro a validation error if a user is not logged in. This is > > because i have a mechanism to display model validation errors in the view > > and dont want to add controller level error displaying handler. Please > > suggest that how can i proceed to check the session in the model. I dont > > think that it is possible to access Session component in the model. Is It?
> On Mar 6, 1:09 pm, Baz <bazil...@gmail.com> wrote: > > Anything is possible...
> > But I think the general consensus is that you should not.
> > With that said, please remember that with MVC we are still dealing with > > classes, member variables and methods here.
> > There is nothing stopping you from assigning a Model member variable in > your > > controller, based on the session, then using that in your Model code as > > needed.
> > On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer < > novice.prog...@gmail.com> > > wrote:
> > > Hello All,
> > > I want to thro a validation error if a user is not logged in. This is > > > because i have a mechanism to display model validation errors in the > view > > > and dont want to add controller level error displaying handler. Please > > > suggest that how can i proceed to check the session in the model. I > dont > > > think that it is possible to access Session component in the model. Is > It?
> What do you suggest then? Should i assign the value of error in controller > to the array that comes out from validation? Doesn't it break MVC paridigm. > I mean model is supposed to give us data and we are still not satisifed with > what it has outputted to us?
> Thanks.
> On Thu, Mar 6, 2008 at 11:39 PM, Baz <bazil...@gmail.com> wrote:
> > Anything is possible...
> > But I think the general consensus is that you should not.
> > With that said, please remember that with MVC we are still dealing with > > classes, member variables and methods here.
> > There is nothing stopping you from assigning a Model member variable in > > your controller, based on the session, then using that in your Model code as > > needed.
> > On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer < > > novice.prog...@gmail.com> wrote:
> > > Hello All,
> > > I want to thro a validation error if a user is not logged in. This is > > > because i have a mechanism to display model validation errors in the view > > > and dont want to add controller level error displaying handler. Please > > > suggest that how can i proceed to check the session in the model. I dont > > > think that it is possible to access Session component in the model. Is It?
yeah thats another way... I got another way though ... will do the controller errors using the hidden divs and enable them in view when controller throws an error.. what say?
On Fri, Mar 7, 2008 at 3:11 AM, Baz <bazil...@gmail.com> wrote: > Dude, you asked the question.
> MVC is a nice model, but if you claim you "NEED" something that it doesn't > support please understand that it's just a bunch of classes.
> On Thu, Mar 6, 2008 at 1:01 PM, Novice Programmer < > novice.prog...@gmail.com> wrote:
> > Hello Baz,
> > What do you suggest then? Should i assign the value of error in > > controller to the array that comes out from validation? Doesn't it break MVC > > paridigm. I mean model is supposed to give us data and we are still not > > satisifed with what it has outputted to us?
> > Thanks.
> > On Thu, Mar 6, 2008 at 11:39 PM, Baz <bazil...@gmail.com> wrote:
> > > Anything is possible...
> > > But I think the general consensus is that you should not.
> > > With that said, please remember that with MVC we are still dealing > > > with classes, member variables and methods here.
> > > There is nothing stopping you from assigning a Model member variable > > > in your controller, based on the session, then using that in your Model code > > > as needed.
> > > On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer < > > > novice.prog...@gmail.com> wrote:
> > > > Hello All,
> > > > I want to thro a validation error if a user is not logged in. This > > > > is because i have a mechanism to display model validation errors in the view > > > > and dont want to add controller level error displaying handler. Please > > > > suggest that how can i proceed to check the session in the model. I dont > > > > think that it is possible to access Session component in the model. Is It?
<novice.prog...@gmail.com> wrote: > yeah thats another way... I got another way though ... will do the > controller errors using the hidden divs and enable them in view when > controller throws an error.. what say?
> Thanks.
> On Fri, Mar 7, 2008 at 3:11 AM, Baz <bazil...@gmail.com> wrote: > > Dude, you asked the question.
> > MVC is a nice model, but if you claim you "NEED" something that it doesn't > support please understand that it's just a bunch of classes.
> > On Thu, Mar 6, 2008 at 1:01 PM, Novice Programmer > <novice.prog...@gmail.com> wrote:
> > > Hello Baz,
> > > What do you suggest then? Should i assign the value of error in > controller to the array that comes out from validation? Doesn't it break MVC > paridigm. I mean model is supposed to give us data and we are still not > satisifed with what it has outputted to us?
> > > Thanks.
> > > On Thu, Mar 6, 2008 at 11:39 PM, Baz <bazil...@gmail.com> wrote:
> > > > Anything is possible...
> > > > But I think the general consensus is that you should not.
> > > > With that said, please remember that with MVC we are still dealing > with classes, member variables and methods here.
> > > > There is nothing stopping you from assigning a Model member variable > in your controller, based on the session, then using that in your Model code > as needed.
> > > > On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer > <novice.prog...@gmail.com> wrote:
> > > > > Hello All,
> > > > > I want to thro a validation error if a user is not logged in. This > is because i have a mechanism to display model validation errors in the view > and dont want to add controller level error displaying handler. Please > suggest that how can i proceed to check the session in the model. I dont > think that it is possible to access Session component in the model. Is It?
> Auth should go in controller, that said you can assign the session
> object to the model $this->Model->Session = $this->Session;
> On Thu, Mar 6, 2008 at 9:50 PM, Novice Programmer
> <novice.prog...@gmail.com> wrote:
> > yeah thats another way... I got another way though ... will do the
> > controller errors using the hidden divs and enable them in view when
> > controller throws an error.. what say?
> > Thanks.
> > On Fri, Mar 7, 2008 at 3:11 AM, Baz <bazil...@gmail.com> wrote:
> > > Dude, you asked the question.
> > > MVC is a nice model, but if you claim you "NEED" something that it doesn't
> > support please understand that it's just a bunch of classes.
> > > On Thu, Mar 6, 2008 at 1:01 PM, Novice Programmer
> > <novice.prog...@gmail.com> wrote:
> > > > Hello Baz,
> > > > What do you suggest then? Should i assign the value of error in
> > controller to the array that comes out from validation? Doesn't it break MVC
> > paridigm. I mean model is supposed to give us data and we are still not
> > satisifed with what it has outputted to us?
> > > > Thanks.
> > > > On Thu, Mar 6, 2008 at 11:39 PM, Baz <bazil...@gmail.com> wrote:
> > > > > Anything is possible...
> > > > > But I think the general consensus is that you should not.
> > > > > With that said, please remember that with MVC we are still dealing
> > with classes, member variables and methods here.
> > > > > There is nothing stopping you from assigning a Model member variable
> > in your controller, based on the session, then using that in your Model code
> > as needed.
> > > > > On Thu, Mar 6, 2008 at 10:49 AM, Novice Programmer
> > <novice.prog...@gmail.com> wrote:
> > > > > > Hello All,
> > > > > > I want to thro a validation error if a user is not logged in. This
> > is because i have a mechanism to display model validation errors in the view
> > and dont want to add controller level error displaying handler. Please
> > suggest that how can i proceed to check the session in the model. I dont
> > think that it is possible to access Session component in the model. Is It?
On Mar 6, 8:56 pm, rtconner <rtcon...@gmail.com> wrote:
> global $SESSION;
> $SESSION = $this->Session;
> screw this not getting at the session from the model crap, there are
> exceptions to every rule and this is one of them
rtconner:
OMG u r teh N00Bzorz!!1one!
Novice Programmer:
There are two right ways of doing this. One is to make the session a
formal part of your domain model, i.e. model it. This allows it to
interact with other models at the model level. The model, like the
view, should never directly query a tier outside its own. The other
is to use a callback to notify the model of the user's state.
Assuming you are following proper convention, this can be handled
across your entire application in one fell swoop:
class AppController extends Controller {
var $components = array("Auth");
function beforeFilter() {
$this->{$this->modelClass}->setUserState($this->Auth->user());
}
}
class AppModel extends Model {
function setUserState($user) {
// Handle authentication data/set local variables in prep for
validation
}
}
Hope that helps. If you're not able to get it to work, reply to this
thread and myself or someone else knowledgeable in proper OO/MVC
design will respond.
Ya Novice Programmer, don't listen to me. It's not recomended.
Nate:
You be happy to know, one of my favourite bootrap functions ..
function user($key = null) {
global $AUTH_COMPONENT;
return $AUTH_COMPONENT->user($key);
> Ya Novice Programmer, don't listen to me. It's not recomended.
> Nate:
> You be happy to know, one of my favourite bootrap functions ..
> function user($key = null) {
> global $AUTH_COMPONENT;
> return $AUTH_COMPONENT->user($key);}
> Dude, Rob, you can be as proletarian as you want in your own
> applications, just don't come polluting our mailing list with your
> uneducated drivel.
> On Mar 6, 9:25 pm, rtconner <rtcon...@gmail.com> wrote:
> > Ya Novice Programmer, don't listen to me. It's not recomended.
> > Nate:
> > You be happy to know, one of my favourite bootrap functions ..
> > function user($key = null) {
> > global $AUTH_COMPONENT;
> > return $AUTH_COMPONENT->user($key);}