Php Zend Framework从另一个控制器访问方法时出现问题 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'; } }
我一直试图使用_forward方法从另一个控制器访问我的IndexController中的一个方法,但它似乎不起作用。我试过:Php Zend Framework从另一个控制器访问方法时出现问题 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'; } },php,zend-framework,zend-controller,Php,Zend Framework,Zend Controller,我一直试图使用_forward方法从另一个控制器访问我的IndexController中的一个方法,但它似乎不起作用。我试过: $this->_forward('permissions', 'Index') $this->_forward('permissions', 'index') $this->_forward('permissions', 'IndexController') $this->_forward('permissions', 'indexcontrol
$this->_forward('permissions', 'Index')
$this->_forward('permissions', 'index')
$this->_forward('permissions', 'IndexController')
$this->_forward('permissions', 'indexcontroller')
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';
}
}
这些都不起作用。这是我的密码
控制器
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';
}
}
第二控制器
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';
}
}
<?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;
}
}
\u forward
仅用于调用控制器操作,而不是常规方法
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';
}
}
\u forward('index')
实际上是指方法indexAction()
\u forward
仅用于调用控制器操作,而不是常规方法
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';
}
}
\u forward('index')
实际上指的是方法indexAction()
更改如下:
public function permissionsAction(){
// return the permissions
return 'publish_stream, read_stream, friends_likes';
}
为此:
更改此项:
public function permissionsAction(){
// return the permissions
return 'publish_stream, read_stream, friends_likes';
}
为此:
我没有特别清楚地思考,相反,我只是把代码放在一个模型中,从他们的模型中访问数据。我没有特别清楚地思考,相反,我只是把代码放在一个模型中,从他们的模型中访问数据。如果你想让多个控制器共享一个方法,你应该查看Zend action helpers,而不是。。。如果你想让多个控制器共享一个方法,你应该查看Zend action helpers。。。或者使用它们扩展其他通用控制器。
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';
}
}