XF 2.3 Accessed unknown getter

Status
Not open for further replies.

Basenotes

Well-known member
I'm following Kiers tutorial that he posted a few years back, and I'm getting this error when I get to the end of Part 10. I've looked and looked for hours but I can't work out what I'm doing wrong. (Im adapting the code for reviews so it's called Reviews/Review rather than Pad/Note)

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

I've got to the end of the video where it is supposed to list all the notes/reviews by a particular user, but I'm getting this error each time :



Template errors
  • Template public:bn_reviews_user: [E_USER_WARNING] Accessed unknown getter 'Reviews' on XF:User[1] (src/XF/Mvc/Entity/Entity.php:224)



Reviews/Entity/User.php
PHP:
<?php

namespace Basenotes\Reviews\Entity;

use XF\Mvc\Entity\Structure;

class User extends \XF\Entity\User
{
    public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);

        $structure->relations['Reviews'] = [
            'entity' => 'Basenotes\Reviews:Review',
            'type' => self::TO_MANY,
            'conditions' => 'user_id',
        ];

        return $structure;
    }
}

Reviews/Pub/Controller/Review.php (snippet)

PHP:
public function actionUser()
{

if ($userId = $this->filter('user_id', 'uint')) {

$user = $this->assertRecordExists('XF:User', $userId);

               }

$viewParams = [
'user' => $user ?? null,
        'users' => $this->finder('XF:User'),
    ];

    return $this->view('Basenotes\Reviews:Review\User', 'bn_reviews_user', $viewParams);


}


bn_reviews_user.html

HTML:
<xf:title>Users</xf:title>
<xf:if is="{$user}">
    <h2>{$user.username}</h2>
</xf:if>
{{ dump($user) }}
{{ dump($users) }}
<ul>
    <xf:foreach loop="$user.Reviews" key="$review_id" value="$review">
       <li>
          {$review.title} (<xf:date time="{$review.review_date}" />)
</li>
    </xf:foreach>
</ul>

<ul>
    <xf:foreach loop="$users" value="$u">
       <li><a href="{{link('reviews/user', null, {'user_id': $u.user_id})}}">{$u.username}</a></li>
    </xf:foreach>
</ul>

Class Extension

Screenshot 2025-05-09 at 14.47.00.webp
 
The class should extend a virtual XFCP_User class (XFCP = XenForo Class Proxy). It's also conventional to nest class extensions under the original namespace/directory (Basenotes\Reviews\XF\Entity):

PHP:
<?php

namespace Basenotes\Reviews\XF\Entity;

use XF\Mvc\Entity\Structure;

class User extends XFCP_User
{
    // ...
}
 
It's also what Kier does in the video:
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Kier is an AI, confirmed.

So would you care to elaborate on why someone would use \XF\Entity\User vs XFCP_User? Or did you just comment to keep your account seem active?
 
You’ll always have to do that if you want your class extensions to actually work.

Normal PHP class extensions function like you’d expect, this is about extending core classes (or classes from other add-ons). That entire mechanism functions on the XenForo Class Proxy system.

Haven’t seen the video but likely just an honest mistake.
 
Jeremy, I’ve never done something like \XF\Entity\User, I’ve used XFCP_User and it works. Am I wrong?
 
He was just making a light-hearted joke that Kier is an AI because he made that mistake in the video OP was referencing.
 
Honestly, all that served is to confuse people even more, he should have answered professionally like you do, instead of injecting BS into a conversation.
 
Honestly, all that served is to confuse people even more, he should have answered professionally like you do, instead of injecting BS into a conversation.
The solution has been the same for nearly 10 years for just XF 2.x and longer counting XF 1?
 
If that’s true, then it wasn’t on purpose. It’s ok to have a sense of humor at work. It’s also ok to accidentally misread the tone of prose.

Anyway, XFCP_ is correct for the class extension system :)
 
If that’s true, then it wasn’t on purpose. It’s ok to have a sense of humor at work. It’s also ok to accidentally misread the tone of prose.

Anyway, XFCP_ is correct for the class extension system :)

Which is cool, but coming from someone that barely participates in the community is is a bit off putting ( considering he should be professional) if it had been you then it might have been funny.
 
I’m happy to help out here where I can, but it is and always will be a personal courtesy and I don’t misjudge others who can’t or don’t do the same.

Anyway since the original question has been answered definitively I don’t think there’s much more to say about the topic at hand.
 
Status
Not open for further replies.
Back
Top Bottom