how to add variable to viewparams

DroidHost

Well-known member
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();
        }
    }

}
 
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;
        }
 
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 .= ;)
 
Sorry, i've forgotten something

$response->params += array('newVar' => $value);
 
Sorry, i've forgotten something

$response->params += array('newVar' => $value);
thanks
but if this was pass to the view $params = array('mayname'=>'Aaaali');
what is the name should have ? {$myname} in the template ?
 
Your array key is your template variable, so:
array('myname' => 'Aaaali')
{xen:raw $myname}
 
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}
 
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;
 
wtf

what's
('myname'=>'Ali') , "raspberry");
doing in your code?
 
ok ,,,
how can I take a variable from the parent ? to the child

You can fiddle the params in the same way, e.g.

PHP:
$response->params['blah'] = 'No';

Will set the param "blah" to be "No" (it will create it if it didn't actually exist)
 
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');
}
 
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?
 
Top Bottom