• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

how to add variable to viewparams

DroidHost

Well-known member
#1
how to add variable to viewparams of the parent function ...

and how to access a vriable from the parent ....

this is my code
PHP:
class Demo_ControllerPublic_Forum extends XFCP_Demo_ControllerPublic_Forum
{
    public function actionIndex()
    {
        $visitor = XenForo_Visitor::getInstance();
        $visitorId = XenForo_Visitor::getUserId();
        $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);

        $ftpHelper = $this->getHelper('ForumThreadPost');
        $forumFetchOptions = array('readUserId' => $visitor['user_id']);
        $forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName, $forumFetchOptions);

        $forumId = $forum['node_id'];
        $response = parent::actionIndex();
        if ($forumId == 2)
        {
            $mayname = 'ali';//array('mayname'=>'Ali');
            //$this->getadv($response );
            $response->params['myname'] = array();
            $response->params['myname'] += $mayname;
            //array array_merge('$params');
            //array_push($params,('myname'=>'Ali') , "raspberry");
            return $response;
        }
        else
        {
            return $this->responseNoPermission();
        }
    }

}
 

DroidHost

Well-known member
#2
did this but nothing
PHP:
        {
            $mayname = array('mayname'=>'Aaaali');
            //$this->getadv($response );
            $response->viewParams[] .= $mayname;
            //array array_merge('$params');
            //array_push($params,('myname'=>'Ali') , "raspberry");
            return $response;
        }
 
R

ragtek

Guest
#3
did this but nothing
PHP:
        {
            $mayname = array('mayname'=>'Aaaali');
            //$this->getadv($response );
            $response->viewParams[] .= $mayname;
            //array array_merge('$params');
            //array_push($params,('myname'=>'Ali') , "raspberry");
            return $response;
        }
try $response->params += $mayname instead of .=

That's not a string, so you can't add new elements with .= ;)
 
R

ragtek

Guest
#9
if you use mayname, then it's {$mayname}

the params are always 'NAME' => 'VALUE', 'NAME2' => VALUE2

So, to get value into the template, you need {$NAME}, if you want VALUE2 you need {$NAME2}
 

DroidHost

Well-known member
#12
if you use mayname, then it's {$mayname}

the params are always 'NAME' => 'VALUE', 'NAME2' => VALUE2

So, to get value into the template, you need {$NAME}, if you want VALUE2 you need {$NAME2}
not working ,,, I try it before .. !
PHP:
            $params = array('mayname'=>'Aaaali');

            $response->params += $params;
('myname'=>'Ali') , "raspberry");
            return $response;
 
R

ragtek

Guest
#19
1. IMHO your whole code is unnecessary.
You can run the parent action as first, and get all the necessary values!

Example Code:
PHP:
class Ragtek_PC_ControllerAdmin_Page extends
    ##workmode##
    XFCP_Ragtek_PC_ControllerAdmin_Page
    ##workmode end##

    ##developmode##
    XenForo_ControllerAdmin_Page
    ##developmode end##
{


    public function actionEdit()
    {
        $return = parent::actionEdit();
        
        $return->params['page']['ragtek_link_navbar'] = $this->_getRouteModel()->haveSection($return->params['page']['title']);
        return $return;
    }
As you see, i'm accessing here: $this->_getRouteModel()->haveSection($return->params['page']['title']);
direct the variable.

You can do the same!
Your code look like you're extending the forum controller, so you can access the forumId via:

$response = parent::actionIndex();
if ($response instanceof XenForo_ControllerResponse_View AND $response->params['forum']['node_id'] == 2){
$reponse->params += array('myname' => 'Ali');
}
 

DroidHost

Well-known member
#20
Thanks alots

Your code look like you're extending the forum controller, so you can access the forumId via:
-does this mean I dont need to extend forum controller?how to select the place of code execution?