$this->User->isAdmin

How to install and use Contao

$this->User->isAdmin

Postby Medianomaly » Tue Jul 27, 2010 4:22 pm

I'm trying to make a DCA customization very similar to what's here:
http://www.contao.org/custom-configurations.html

Code: Select all
// system/config/dcaconfig.php
// Allow only admins to add articles
if (!$this->User->isAdmin)
{
$GLOBALS['TL_DCA']['tl_article']['config']['closed'] = true;
}

The IF statement is always returning false, even if I'm logged in as an admin. Has this changed since publication (I'm using 2.8.3)?
Brian | Medianomaly
User avatar
Medianomaly
User
 
Posts: 239
Joined: Fri Aug 21, 2009 3:02 am

Re: $this->User->isAdmin

Postby Tru » Tue Jul 27, 2010 4:37 pm

Please show us what is return isAdmin by
Code: Select all

var_dump
($this->User->isAdmin);
 

Is it false?

Have you imported the BackendUser?
Code: Select all

$this
->import('BackendUser', 'User');
 
User avatar
Tru
User
 
Posts: 121
Joined: Sun Jul 26, 2009 1:03 pm

Re: $this->User->isAdmin

Postby Medianomaly » Tue Jul 27, 2010 6:07 pm

Just to clarify, I've added that code directly into /system/config/dcaconfig.php -- as that's what the Developer's Guide recommends.

Inside dcaconfig.php, $this->User returns a valid BackendUser object (it's way too long to post). So I don't think I need to import anything here. I do see a protected variable, 'admin', which is set to "1/true".

Trying to var_dump $this->User->isAdmin in this file gets me a content encoding error, so I can't see directly what it is set to.

However, if I save it --
Code: Select all
$GLOBALS['YOURMOM'] = $this->User->isAdmin;

And spit it out it in my be_main.tpl file --
Code: Select all
echo( $GLOBALS['YOURMOM'] );

It shows blank/false, which it shouldn't, since I'm definitely logged in as an admin.

However, if I just put this into my be_main.tpl file --
Code: Select all
   $this->import('BackendUser', 'User');
   echo($this->User->isAdmin);

It DOES return 1/true.
Brian | Medianomaly
User avatar
Medianomaly
User
 
Posts: 239
Joined: Fri Aug 21, 2009 3:02 am

Re: $this->User->isAdmin

Postby Tru » Tue Jul 27, 2010 8:42 pm

I have just tested this in Contao 2.9 beta1 and looks good:
Code: Select all
// system/config/dcaconfig.php
var_dump($this->User->isAdmin);
 

returns twice true and once null. I think it's either a bug or issue caused by a custom extension.

I hope more advanced developers will help you :)
User avatar
Tru
User
 
Posts: 121
Joined: Sun Jul 26, 2009 1:03 pm

Re: $this->User->isAdmin

Postby ramjet » Wed Jul 28, 2010 12:02 am

Try this to see if it makes a difference... it probably won't but hey!
Code: Select all
$this->import('BackendUser', 'User');
if ($this->User->isAdmin)
{
$GLOBALS['TL_DCA']['tl_article']['config']['closed'] = false;
}else
{
$GLOBALS['TL_DCA']['tl_article']['config']['closed'] = true;
}
ramjet
User
 
Posts: 534
Joined: Sat Jun 20, 2009 12:24 pm


Return to Using Contao

Who is online

Users browsing this forum: No registered users