我發現這個類:Zend的檢查,如果視圖存在 - 類不起作用
https://github.com/lloydwatkin/Demos/blob/master/zendframework/renderifexists/RenderIfExists.php
的代碼看起來是這樣的:
<?php
/**
* View helper to render a view file if it exists
*
* @author Lloyd Watkin
* @since 12/12/2010
* @package Pro
* @subpackage View
*/
/**
* View helper to render a view file if it exists
*
* @author Lloyd Watkin
* @since 12/12/2010
* @package Pro
* @subpackage View
*/
class Pro_View_Helper_RenderIfExists
extends Zend_View_Helper_Abstract
{
/**
* Errors
*
* @var string
*/
const INVALID_FILE = 'Invalid file parameter';
/**
* Holds file name for processing
*
* @var string
*/
protected $_file;
/**
* Takes a products options array and converts to a formatted string
*
* @param string $file
* @return string
*/
public function renderIfExists($file)
{
if (!is_string($file) || empty($file)) {
throw new Zend_View_Exception(self::INVALID_FILE);
}
$this->_file = $file;
if (false === $this->_fileExists()) {
return '';
}
return $this->view->render($file);
}
/**
* Check to see if a view script exists
*
* @return boolean
*/
protected function _fileExists()
{
$paths = $this->view->getScriptPaths();
foreach ($paths as $path) {
if (file_exists($path . $this->_file)) {
return true;
}
}
return false;
}
}
我要檢查,如果一個視圖是否存在;如果確實如此:顯示它。
我已將該文件放在我的/ library /中。當我打電話給$ this-> renderIfExists('info-box.phtml');從控制器我得到這個錯誤:
Message: Method "renderIfExists" does not exist and was not trapped in __call()
我該如何解決這個問題? 在此先感謝!