0

I have been trying to use the _forward method to access a method in my IndexController from another controller, but it won't seem to work. I have tried:

$this->_forward('permissions', 'Index')
$this->_forward('permissions', 'index')
$this->_forward('permissions', 'IndexController')
$this->_forward('permissions', 'indexcontroller')

None of which have worked. Here is my code.

Controller

class IndexController extends Zend_Controller_Action
{

    /**
     * facebookConfig
     * 
     * @var mixed
     * @access protected
     */
    protected $facebookConfig;

    /**
     * signed_request
     * 
     * @var mixed
     * @access protected
     */
    protected $signed_request;

    /**
     * facebookConfig
     * 
     * @var mixed
     * @access protected
     */
    protected $permissions;

    /**
     * init function.
     * 
     * @access public
     * @return void
     */
    public function init()
    {
        // get the model
        $this->app = new Application_Model_Admin();

        // get config data
        $this->facebookConfig =  $this->app->configData();

        // get the apps permissions
        $this->permissions = $this->permissions();

        // get the data for the head
        $data = $this->app->configData();
        if(empty($data->ogimage))
            $data->ogimage = '';

        // set the page title
        $this->view->headTitle($data->title, 'PREPEND');

        // set the meta data
        $this->view->headMeta()->setName('fb:app_id',       $data->appid);
        $this->view->headMeta()->setName('og:type',         $data->ogtype);
        $this->view->headMeta()->setName('og:title',        $data->ogtitle);
        $this->view->headMeta()->setName('og:description',  $data->ogdesc);
        $this->view->headMeta()->setName('og:url',          $data->applink);
        $this->view->headMeta()->setName('og:image',        $data->ogimage);
    }

    /**
     * permissions function.
     * 
     * @access public
     * @return void
     */
    public function permissions(){
        // return the permissions
        return 'publish_stream, read_stream, friends_likes';
    }

}

Second Controller

<?php

class ThanksController extends Zend_Controller_Action
{

    /**
     * facebookConfig
     * 
     * @var mixed
     * @access protected
     */
    protected $permissions;

    /**
     * init function.
     * 
     * @access public
     * @return void
     */
    public function init()
    {
        // get the model

        // get the permissions
        $this->permissions = $this->_forward('permissions', 'index');
        print_r('<pre>');var_dump($this->_forward('permissions', 'index'));print_r('</pre>');die;

    }
 }
2
  • 1
    If you want multiple controllers to share a method, you should look into Zend action helpers instead. Commented Aug 22, 2012 at 17:30
  • .. or extend other common controller with them. Commented Aug 23, 2012 at 7:25

3 Answers 3

2

_forward is used only to call controller actions, not regular methods

_forward('index') actually refers to method indexAction()

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

Comments

1

Change this:

public function permissions(){
    // return the permissions
    return 'publish_stream, read_stream, friends_likes';
}

to this:

public function permissionsAction(){
    // return the permissions
    return 'publish_stream, read_stream, friends_likes';
}

Comments

0

I wasn't thinking particularly clearly, instead I just put the code in a model and accessed the data from their.

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.