我的 zend 应用程序中有一个用户定义类(默认)
应用程序/库/Custom_/Custom_Test.php
我想在 indexController.php 的 getvalueAction() 中使用它
我尝试在 [production] 的 application.ini 中包含以下行
autoloaderNamespaces.custom = "Custom_"
我不想使用简单的包含函数,也无法在 getvalueAction() 中实例化它。怎么做 ?
- 使用网豆
- Ubuntu 11.10
- 我是zend新手
谢谢你。
PS:为了清楚起见,我将在下面显示我的代码
索引控制器.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');
}
}
在 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>
在 getvalue.phtml 里面
<h1><?php echo "Final value id " . $this->escape($this->result); ?></h1>
索引.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();
应用程序.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;
}
}
?>