Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:15:46+00:00 2026-06-02T18:15:46+00:00

I have a user define class inside my zend application(as default) application/library/Custom_/Custom_Test.php I want

  • 0

I have a user define class inside my zend application(as default)

application/library/Custom_/Custom_Test.php

I want to use it in getvalueAction() in side indexController.php

I have tried included following line in application.ini at [production]

autoloaderNamespaces.custom = "Custom_"

I don’t want to use simple include function and I can’t instantiate it inside getvalueAction(). How to do that ?

  • using netbeans
  • ubuntu 11.10
  • I’m new to zend

Thank you.

PS: I will show my code bellow for the sake of clarity

indexController.php

<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {}

    public function indexAction()
    {}

    public function getvalueAction() {
        $request = $this->getRequest();
        $numb = $request->getParam('numb');

        $result = Test::testFunction($numb);
        $this->view->assign('result',$result);
    }

    public function inputAction() {
        $this->view->assign('action','getvalue');
    }
}

inside the input.phtml

  <form name="enterNumber" method="post" action="<?php echo $this->escape($this->action)?>" >

      input a number :
      <input type="text" name="numb"/> <br/>
      <input type="submit" value="Submit" />


  </form>

inside the getvalue.phtml

  <h1><?php echo "Final value id " . $this->escape($this->result); ?></h1>

index.php

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

application.ini

[production]
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.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

[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

Custom_Test.php

<?php

    class CustomTest{

        function testFunction($a) {

            return $a*2;
        }
    }

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:15:49+00:00Added an answer on June 2, 2026 at 6:15 pm

    Action helper is what you need.

    since you said

    I want to use it in getvalueAction() in side indexController.php

    According to official Zend Framework’s Website

    Action Helpers allow developers to inject runtime and/or on-demand
    functionality into any Action Controllers that extend
    Zend_Controller_Action. Action Helpers aim to minimize the necessity
    to extend the abstract Action Controller in order to inject common
    Action Controller functionality.

    i assume you want to use action helper, since action helper was specifically designed for this purpose.

    Step 1.
    You need to tell the helper broker where your action helpers are, i usually do that in my application.ini file, but you can do that in your frontController or Bootstrap file too.

    #if you are using application.ini, in your application.ini add the following
    resources.frontController.actionHelperPaths.Custom_Action_Helper = APPLICATION_PATH "/../library/Custom/helpers"
    

    Step 2:
    Creating the Action Helper class, you have to make sure the class extends Zend_Controller_Action_Helper_Abstract and place the file in defined helper directory in your case it is Library/Custom/helpers

    and create the action helper like this

    class Custom_Action_Helper_Test extends Zend_Action_Helper_Abstract
    {
        public function random()
        {
            return 'foo';
        }
    }
    

    now helpers are ready to be used inside any controller. it may be called by using following syntax.

    echo $this->_helper->Test->random();
    

    hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I have a class which has properties of user-defined types like
So I have a file for constants. I want to let user define them
I want to make a PHP class, lets say Myclass.php. Now inside that class
If I have a user defined default constructor in my Test class, and what
Suppose I have an array of a objects of user defined class. Wanted to
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have a class that defined a user defined operator for a TCHAR*, like
I have a class Bar that has a user-defined list of config keys and
I have some logic, which defines and uses some user-defined types, like these: class
I have three tables which are defined as: class User(Base): __tablename__ = 'users' id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.