XF 2.0 Extending the class of an existing

AndrewSimm

Well-known member
I am trying to add a count of articles into the stats of a user profile. I extended the class in the admin panel and I am trying to figure out how to make the variable available in the template. Basically, I am just trying to add to the viewAction of Members.

I have read the documents here but cannot seem to get it to work. When I use {$articles} in the template (using TMS) nothing shows. I get the title so I know my template modification is fine.


PHP:
namespace Andrew\Articles\XF\Pub\Controller;

use XF\Mvc\ParameterBag;

class Member extends XFCP_Member
{
    public function actionArticleStats(ParameterBag $params) {

        $reply = parent::actionView();

        if ($reply instanceof \XF\Mvc\Reply\View)
        {
            $articles = 2;

            $reply->setParam('articles', $articles);
        }

        return $reply;

    }

}
 
If you're wanting to add new template param, consider extending the view instead.

Here's an example from our DB Security mod:

PHP:
namespace DBTech\Security\XF\Pub\View\Account;

class TwoStep extends XFCP_TwoStep
{
    public function renderHtml()
    {
        /** @var \DBTech\Security\XF\Repository\UserTfaTrusted $tfaTrustRepo */
        $tfaTrustRepo = \XF::repository('XF:UserTfaTrusted');

        $this->params['otherDevices'] = $tfaTrustRepo->getUserTrustedRecords(
            \XF::visitor()->user_id,
            (is_null($this->params['currentTrustRecord']) ? null : $this->params['currentTrustRecord']['trusted_key'])
        );
    }
}
This would make the variable $otherDevices available in the template.

Fillip
 
If you're wanting to add new template param, consider extending the view instead.

Here's an example from our DB Security mod:

PHP:
namespace DBTech\Security\XF\Pub\View\Account;

class TwoStep extends XFCP_TwoStep
{
    public function renderHtml()
    {
        /** @var \DBTech\Security\XF\Repository\UserTfaTrusted $tfaTrustRepo */
        $tfaTrustRepo = \XF::repository('XF:UserTfaTrusted');

        $this->params['otherDevices'] = $tfaTrustRepo->getUserTrustedRecords(
            \XF::visitor()->user_id,
            (is_null($this->params['currentTrustRecord']) ? null : $this->params['currentTrustRecord']['trusted_key'])
        );
    }
}
This would make the variable $otherDevices available in the template.

Fillip

The only two views I see are Find and WarnFill. What would be the base for this view?
 
Back
Top Bottom