accessing identity in templates directly

1 view
Skip to first unread message

Karan

unread,
Sep 22, 2010, 6:28:36 PM9/22/10
to Konstrukt
Is there a way for templates to access the current context identity in
the template directly, without it having to be passed in from
controllers explicitly?

troels knak-nielsen

unread,
Sep 24, 2010, 9:13:09 AM9/24/10
to kons...@googlegroups.com
If you use the standard k_Template, the current context is available
in $GLOBALS['k_current_context']. I strongly recommend that you never
access this directly from within a template. Instead, create a helper
function. Like:

function identity() {
return $GLOBALS['k_current_context']->identity();
}

--
troels

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

Karan

unread,
Sep 24, 2010, 1:12:53 PM9/24/10
to kons...@googlegroups.com
I tried exactly what you said, but i get a protected access error when i try to do $GLOBALS['k_current_context']->identity()->user(). I think it's protected to k_Contexts

Karan

unread,
Sep 24, 2010, 4:14:16 PM9/24/10
to kons...@googlegroups.com
Okay for the record, i realized the user *property* is protected, but the accessor identity()->user() and ->anonymous() is not.

Thanks for the tip. 

troels knak-nielsen

unread,
Sep 25, 2010, 4:50:43 AM9/25/10
to kons...@googlegroups.com
Glad you figured it out.

Most (all?) properties are declared protected in the konstrukt code base.

--
troels

Reply all
Reply to author
Forward
0 new messages