1

Hi am new to zendframewrok,

In my controller, I have public function with arguments like this

    public function ArrayRetrive($array, $todelete)
{
    $res='';
    if(@array_key_exists($todelete, $array)) {
        $res=$array[$todelete];
    }
    else{
    foreach( $array as $key=>$value )
    {
        if (is_array($array[$key]) && array_key_exists($todelete, $array[$key])) {
        $res=$array[$key][$todelete];
        }
    }
    }
    return $res;
}

Now i want to access this function in view index.phtml,

I don't know how to do that?am stuck here.

Please help me any one

5
  • In your controller add $this->view->res=$res; and call the value in index.phtml as <?php echo $this->res;?> Commented Feb 10, 2015 at 5:46
  • How it is work? I called that res variable inside of function. what am exactly asking I want to access this function from view like $this->ArrayRtrive($array, 'status') Commented Feb 10, 2015 at 6:04
  • @use3535066 - you have to assign the value in controller and then only you can access the value in view. Commented Feb 10, 2015 at 6:06
  • am trying this one but it's not working? Because, actually I need to pass the function argument from view page for example I have big multidimensional associative array, I want to took only one value from the array, so am passing the array & key into this function it will return the output. Commented Feb 10, 2015 at 6:25
  • write a custom view helper and assign the ($array, 'status') to your view. Commented Feb 10, 2015 at 8:24

1 Answer 1

1

You need to build a view helper. Here it is a good/fast tutorial: https://samsonasik.wordpress.com/2012/07/20/zend-framework-2-create-your-custom-view-helper/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.