XF 2.0 how to add new class extensions to XFRM

HQCoder

Member
I have dealt with this problem

i write this code:

PHP:
namespace HQCoder\ResourceVote\Pub\Controller;
class ResourceItem extends XFCP_ResourceItem
{
    public function actionIndex(XF\Mvc\ParameterBag $params)
    {
        $parent = parent::actionIndex($params);
        return $parent;
    }
   
}

and it show error
ErrorException: [E_STRICT] Declaration of HQCoder\ResourceVote\Pub\Controller\ResourceItem::actionIndex() should be compatible with XFRM\Pub\Controller\ResourceItem::actionIndex(XF\Mvc\ParameterBag $params) in src\addons\HQCoder\ResourceVote\Pub\Controller\ResourceItem.php at line 20
can you give me the way to add new class extensions to XFRM?
 
Last edited:
Code:
namespace HQCoder\ResourceVote\Pub\Controller;

use XF\Mvc\ParameterBag;

class ResourceItem extends XFCP_ResourceItem
{
    public function actionIndex(ParameterBag $params)
    {
        $parent = parent::actionIndex($params);
        return $parent;
    }
}

Also for clarity that you're extending the XFRM, you should place the file in the XFRM\Pub\Controller folder in your add-on.
HQCoder\ResourceVote\XFRM\Pub\Controller
 
Code:
namespace HQCoder\ResourceVote\Pub\Controller;

use XF\Mvc\ParameterBag;

class ResourceItem extends XFCP_ResourceItem
{
    public function actionIndex(ParameterBag $params)
    {
        $parent = parent::actionIndex($params);
        return $parent;
    }
}
thanks mr snog.
By the way here I hope you help me this problem in xf2
how to use XF\Pub\View in XF2 addon? i use this code to return an json view :
Code:
return $this->view('HQCoder\ResourceVote:ResourceItem\Find', '', $viewParams);

But it does not seem right
 
You need a template name in there, And use a short name for your add-on (though I don't think that you would cause a problem. I don't really know)..
Code:
return $this->view('ResourceVote:ResourceItem\Find', 'TEMPLATE_NAME', $viewParams);
 
You need a template name in there, And use a short name for your add-on (though I don't think that you would cause a problem. I don't really know)..
Code:
return $this->view('ResourceVote:ResourceItem\Find', 'TEMPLATE_NAME', $viewParams);

thanks you again, in XF/Pub/Controler/Member.php
Code:
public function actionFind()
    {
        $q = ltrim($this->filter('q', 'str', ['no-trim']));

        if ($q !== '' && utf8_strlen($q) >= 2)
        {
            /** @var \XF\Finder\User $userFinder */
            $userFinder = $this->finder('XF:User');

            $users = $userFinder
                ->where('username', 'like', $userFinder->escapeLike($q, '?%'))
                ->isValidUser(true)
                ->fetch(10);
        }
        else
        {
            $users = [];
            $q = '';
        }

        $viewParams = [
            'q' => $q,
            'users' => $users
        ];
        return $this->view('XF:Member\Find', '', $viewParams);
    }

you can see at line 1014
return $this->view('XF:Member\Find', '', $viewParams);
the return do not have a template name. because it return Json value
 
Json is handled differently. Look for $reply->setJsonParams in the XF code and how it's built/returned.
 
Json is handled differently. Look for $reply->setJsonParams in the XF code and how it's built/returned.
thanks you. I change it to
return $this->view('HQCoder\ResourceVote\Pub\View\ResourceItem\Find', 'TEMPLATE_NAME', $viewParams);
it worked
thanks again :p:p:p
 
Back
Top Bottom