0

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 userController which is in user module? i am getting a fatal error when trying to do this

2 Answers 2

2

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.

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

8 Comments

the common features are in default controller and it is in module default. i want to get these default controller in all other module controllers. i tried with action helper but i cannot able to get Zend_Controller_Request_Abstract object in the action helper.
i am trying to implement the solution described in stackoverflow.com/questions/583636/….. but i have a modular structure... so as mention in the given link i have a base controller in the default module which cannot be able to extend to other controller. is there a better solution for this situation?
@guny I just can repeat myself: The common features should not be in a requestable controller. An by the way its just way much easier to implement one generic parent controller-class inside your personal library ;)
actually i am newbie in zend framework and i have learnt about action helper, plugin in library but how cum a parent controller class inside ?
|
2

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');
    }
}

1 Comment

my user class class User_IndexController extends Default_IndexController { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body // if ($this->getRequest()->isPost()) // { // $this->view->name=$_POST['username']; // } } class Default_IndexController extends Zend_Controller_Action {} }

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.