views:

41

answers:

2

Hi

I am using Zend Framework v 1.10

I have created a custom function in the bootstrap file:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    public function init(){   }

    public function helloworld(){ echo 'hello';}
}
?>

How do I call the helloworld() function from an Action within the Index Controller?

Any help will be appreciated.

Thanks

+3  A: 
$this->getFrontController()->getParam('bootstrap')->helloworld();

should work. But I can't think of any reason why you would want to do this - the bootstrap is for initialising application resources, its job is done long before controllers get involved. Perhaps whatever you are doing in the method should be a resource or in a controller plugin?

Tim Fountain
Then what is the difference between the bootstrap file and the index.php file that sits under the public folder which I found under the Quickstart code sample on the zend official site?
Shouvik
Both are part of the initialisation process. The index.php calls the bootstrap class.
Tim Fountain
A: 

Any public functions you create in the bootstrap that begin with _init will automatically be called by the bootstrapping code. For instance:

public function _initHelloWorld() { echo 'hello'; }
gnarf