当我开始从事新项目时,我发现了很大的问题。Main.phtml 布局对每个页面执行 26 次。
<?= $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<?
$adapter = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => 'xxx',
'username' => 'xxx',
'password' => 'xxx',
'dbname' => 'xxx'
));
$adapter->query('SET NAMES UTF8');
$debug = $adapter->select()
->from (array ('d'=>'debug'))
->where ('id = ?',1)
->query()
->fetchAll();
$pageCount = $debug [0] ['page'];
$pageCount +=1;
$debug [0]['page'] = $pageCount;
$adapter ->update('debug', $debug [0], $debug [0] ['id']);
?>
<head>
<?= $this->headMeta() ?>
<?= $this->headTitle() ?>
<?= $this->headScript() ?>
<?= $this->headLink() ?>
<?= $this->headStyle() ?>
我将计数放在该布局的头部,以检查它在数据库中的值。每页26次!所以我对 Zend 有疑问。1. 一页一个布局必须执行多少次?2. 我在哪里可以找到零件,谁真正称之为布局?
from
public/index.php. {main}:37
to
zend->view->_run:105
这就是我在调用堆栈中可以找到的所有内容,它在每页上运行 26 次。
引导程序
<?php
class Bootstrap extends ExtZF_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
$moduleAutoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => realpath(dirname(__FILE__) . '/..'),
));
$moduleAutoloader->addResourceTypes(array(
'core' => array(
'namespace' => 'Core',
'path' => 'core'
)
));
}
protected function _initConfig()
{
$this->bootstrap('frontController');
$router = new Zend_Controller_Router_Rewrite();
$request = new Zend_Controller_Request_Http();
$router->route($request);
$module = $request->getModuleName();
$configPath = realpath(dirname(__FILE__) . '/..') . '/configs/modules/' . $module . '.ini';
$config = new Zend_Config_Ini(
$configPath,
APPLICATION_ENV
);
$this->setOptions($config->toArray());
}
protected function _initSettings()
{
$this->_bootstrap('db');
$settingsGateway = new Model_SettingOption_Gateway();
$settings = $settingsGateway->fetch()->toConfig();
App::getConfig()->merge($settings);
}
protected function _initCache()
{
$this->_bootstrap('cachemanager');
Zend_Db_Table_Abstract::setDefaultMetadataCache(
App::getCacheManager()->getCache('database'));
Zend_Locale::setCache(
App::getCacheManager()->getCache('default'));
}
public function _initRoutes()
{
$this->bootstrap('locale');
$langRoute = new Zend_Controller_Router_Route(
':lang',
array(
'lang' => '',
'module' => 'default',
'controller' => 'index',
'action' => 'index'
),
array(
'lang' => "^(ru|en)$"
)
);
$defaultRoute = new Zend_Controller_Router_Route_Module(
array(
'module' => 'default',
'controller' => 'index',
'action' => 'index'
)
);
$defaultRoute = $langRoute->chain($defaultRoute);
$router = $this->getResource('FrontController')->getRouter();
$router->addRoute('langRoute', $langRoute);
$router->addRoute('defaultRoute', $defaultRoute);
}
protected function _initPlugins()
{
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Plugin_ContextAction())
->registerPlugin(new Plugin_ErrorHandler())
->registerPlugin(new Plugin_Ssl())
->registerPlugin(new Plugin_View());
}
protected function _initViewHelpers()
{
ExtZF_Grid::setCellPartial('_partials/grid/cell.phtml');
ExtZF_Grid::setRowPartial('_partials/grid/row.phtml');
ExtZF_Grid::setHeaderPartial('_partials/grid/header.phtml');
ExtZF_Grid::setTablePartial('_partials/grid/table.phtml');
ExtZF_Grid::setHeaderSortPartial('_partials/grid/header-sort.phtml');
ExtZF_Grid::setCheckBoxPartial('_partials/grid/check-box.phtml');
ExtZF_Grid::setFormPartial('_partials/grid/form.phtml');
ExtZF_Grid::setTextFilterPartial('_partials/grid/textFilter.phtml');
ExtZF_Grid::setRangeFilterPartial('_partials/grid/rangeFilter.phtml');
ExtZF_Grid::setSelectFilterPartial('_partials/grid/selectFilter.phtml');
ExtZF_Grid::setFilterButtonsPartial('_partials/grid/filterButtons.phtml');
ExtZF_Grid::setMassActionsPartial('_partials/grid/massActions.phtml');
}
protected function _initHelpers()
{
Zend_Controller_Action_HelperBroker::addPath(
'ExtZF/Controller/Action/Helper/', 'ExtZF_Controller_Action_Helper'
);
}
}
索引控制器
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
}
}
索引.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'));
set_include_path(
implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../library/ExtZF'),
get_include_path()
)
));
// Zend_Application
require_once 'Zend/Application.php';
require_once 'Zend/Config/Ini.php';
require_once APPLICATION_PATH . '/App.php';
// Set configuration
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',
APPLICATION_ENV, true);
App::setConfig($config);
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
$config
);
$application->bootstrap()
->run();