开发者

extend controller in zend Controller

开发者 https://www.devze.com 2023-01-26 12:25 出处:网络
hi how to extend a controller class from another controller class inside a module? for eg: i have a module default and a controller defaultController

hi how to extend a controller class from another controller class inside a module? for eg: i have a module default and a controller defaultController i want to extend the default controller in userCont开发者_运维百科roller which is in user module? i am getting a fatal error when trying to do this


For re-useable controller functionality you should either use a common parent class for both controllers, instead extending one controller by another, or you should use action-helpers.


Try too look at this example

My directory struckture

+application
+-configs
+-modules
+--front
+---controllers
+---views
+----helpers
+----scripts
+-----index
+--user
+---controllers
+---views
+----helpers
+----scripts
+-----index
+library
+public

application/configs/application.ini

[production]
Autoloadernamespaces[] = "Zend_"
Autoloadernamespaces[] = "My_"

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"

bootstrap.class = "Bootstrap"
appnamespace = "Application"

resources.modules[] = ''
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.defaultModule = "front"
resources.frontController.throwErrors = false

resources.router.routes.default.route = ":module/:controller/:action/*"
resources.router.routes.default.defaults.module = front
resources.router.routes.default.defaults.controller = index
resources.router.routes.default.defaults.action = index

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

application/bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}

application/modules/front/controllers/IndexController.php

<?php
/**
 * IndexController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class IndexController extends My_Controller_Action_Abstract
{
    /**
     * The default action - show the home page
     */
    public function indexAction ()
    {
        echo('Front Controller');
    }
}

application/modules/user/controllers/IndexController.php

<?php
/**
 * IndexController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class User_IndexController extends My_Controller_Action_Abstract
{
    /**
     * The default action - show the home page
     */
    public function indexAction ()
    {
        echo('User Controller');
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号