zendアプリケーション内にユーザー定義クラスがあります(デフォルトとして)
application / library / Custom_ / Custom_Test.php
indexController.php側のgetvalueAction()で使用したい
[本番]のapplication.iniに次の行を含めてみました
autoloaderNamespaces.custom = "Custom_"
単純なinclude関数を使用したくないので、getvalueAction()内でインスタンス化できません。どうやってするか ?
- NetBeansを使用する
- ubuntu 11.10
- 私はzendに不慣れです
ありがとうございました。
PS:わかりやすくするために、以下にコードを示します。
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');
}
}
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>
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;
}
}
?>