-
$this->User->isAdmin
I'm trying to make a DCA customization very similar to what's here:
http://www.contao.org/custom-configurations.html
Code:
// 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)?
-
Re: $this->User->isAdmin
Please show us what is return isAdmin by
[code=php:b2sijnc0]<span class="syntaxdefault">
var_dump</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">User</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">isAdmin</span><span class="syntaxkeyword">);
</span><span class="syntaxdefault">*</span>[/code:b2sijnc0]
Is it false?
Have you imported the BackendUser?
[code=php:b2sijnc0]<span class="syntaxdefault">
$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">import</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'BackendUser'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">*</span><span class="syntaxstring">'User'</span><span class="syntaxkeyword">);
</span><span class="syntaxdefault">*</span>[/code:b2sijnc0]
-
Re: $this->User->isAdmin
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:
$GLOBALS['YOURMOM'] = $this->User->isAdmin;
And spit it out it in my be_main.tpl file --
Code:
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:
$this->import('BackendUser', 'User');
echo($this->User->isAdmin);
It DOES return 1/true.
-
Re: $this->User->isAdmin
I have just tested this in Contao 2.9 beta1 and looks good:
[code=php:2rfww3q1]<span class="syntaxdefault">
</span><span class="syntaxcomment">//*system/config/dcaconfig.php
</span><span class="syntaxdefault">var_dump</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">User</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">isAdmin</span><span class="syntaxkeyword">);
</span><span class="syntaxdefault">*</span>[/code:2rfww3q1]
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 :)
-
Re: $this->User->isAdmin
Try this to see if it makes a difference... it probably won't but hey!
Code:
$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;
}