Results 1 to 5 of 5

Thread: $this->User->isAdmin

  1. #1
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default $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)?
    Brian

  2. #2
    User
    Join Date
    07-26-09.
    Posts
    175

    Default 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]

  3. #3
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default 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.
    Brian

  4. #4
    User
    Join Date
    07-26-09.
    Posts
    175

    Default 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

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default 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;
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •