Quantcast

Checking user session in model

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Checking user session in model

Novice Programmer
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?

--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Baz L
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Matt Curry

Or you can cheat and use $_SESSION...but you didn't hear that from me.

-Matt
www.pseudocoder.com

On Mar 6, 1:09 pm, Baz <[hidden email]> 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 <[hidden email]>
> 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?
>
> > --
> > Thanks & Regards,
> > Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Novice Programmer
In reply to this post by Baz L
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 <[hidden email]> 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 <[hidden email]> 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?

--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).







--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Novice Programmer
In reply to this post by Matt Curry
$_SESSION... :(.. .This will even break cake paradigms along with the MVC paradigms.. one on one free bonanza... :).. Just kidding..

On Fri, Mar 7, 2008 at 12:24 AM, MattC <[hidden email]> wrote:

Or you can cheat and use $_SESSION...but you didn't hear that from me.

-Matt
www.pseudocoder.com

On Mar 6, 1:09 pm, Baz <[hidden email]> 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 <[hidden email]>
> 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?
>
> > --
> > Thanks & Regards,
> > Novice (http://ishuonweb.wordpress.com/).




--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Baz L
In reply to this post by Novice Programmer
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Novice Programmer
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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?

--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).







--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).







--
Thanks & Regards,
Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Dardo Sordi Bogado

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
<[hidden email]> 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 <[hidden email]> 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
> <[hidden email]> 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 <[hidden email]> 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
> <[hidden email]> 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?
> > > > >
> > > > > --
> > > > > Thanks & Regards,
> > > > > Novice (http://ishuonweb.wordpress.com/).
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > > --
> > > Thanks & Regards,
> > > Novice (http://ishuonweb.wordpress.com/).
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
>
>
> --
> Thanks & Regards,
> Novice (http://ishuonweb.wordpress.com/).
>  >
>

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

rtconner

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

On Mar 6, 6:33 pm, "Dardo Sordi Bogado" <[hidden email]> wrote:

> 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
>
> <[hidden email]> 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 <[hidden email]> 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
> > <[hidden email]> 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 <[hidden email]> 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
> > <[hidden email]> 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?
>
> > > > > > --
> > > > > > Thanks & Regards,
> > > > > > Novice (http://ishuonweb.wordpress.com/).
>
> > > > --
> > > > Thanks & Regards,
> > > > Novice (http://ishuonweb.wordpress.com/).
>
> > --
> > Thanks & Regards,
> > Novice (http://ishuonweb.wordpress.com/).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Nate Abele

On Mar 6, 8:56 pm, rtconner <[hidden email]> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

rtconner

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);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Nate Abele

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 <[hidden email]> 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);}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

Vangel

The idea of using session as model is interesting.

On Mar 7, 10:31 am, nate <[hidden email]> wrote:

> 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 <[hidden email]> 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);}

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking user session in model

grigri

> The idea of using session as model is interesting.

You mean like this: https://trac.cakephp.org/ticket/1163 ?

Yeah, I agree. Could be very interesting.

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

Loading...