本文整理汇总了PHP中Phalcon\Mvc\View::setLayoutsDir方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setLayoutsDir方法的具体用法?PHP View::setLayoutsDir怎么用?PHP View::setLayoutsDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setLayoutsDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* @param Event $event
* @param Application $application
* @return mixed
*/
public function boot(Event $event, Application $application)
{
$config = $application->getConfig()->application;
if (isset($config->view) && $config->view !== false) {
$view = new View();
$view->setViewsDir($config->view->viewsDir);
$view->setLayoutsDir($config->view->layoutsDir);
$view->setLayout($config->view->layout);
$application->getDI()->setShared('view', $view);
}
}
示例2: registerServices
public function registerServices(DiInterface $di)
{
global $config;
$di->setShared('url', function () use($config) {
$url = new UrlResolver();
$url->setBaseUri($config->backend->baseUri);
return $url;
});
$di->setShared('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers");
return $dispatcher;
});
$di->setShared('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->backend->viewsDir);
$view->setLayoutsDir('layouts/');
$view->setPartialsDir('partials/');
$view->registerEngines(array('.phtml' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
});
}
示例3: registerServices
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$config = (include __DIR__ . "/config/config.php");
$di['dispatcher'] = function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers");
return $dispatcher;
};
/**
* Setting up the view component
*/
$di['view'] = function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('../../common/layouts/backend/');
$view->setTemplateAfter('main');
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new MySQLAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
};
}
示例4: registerServices
/**
* Register specific services for the module
*/
function registerServices(\Phalcon\DiInterface $di)
{
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
return $dispatcher;
});
$config = $di->getShared('config');
$di->set('view', function () use($config, $di) {
$view = new View();
$router = $di->getShared('router');
/*
* @todo 给layouts等目录统一变量
* */
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('/../../../layouts/');
// 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
$view->setLayout('index');
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
}, true);
}
示例5: registerServices
public function registerServices(DiInterface $di)
{
$di['dispatcher'] = function () {
$eventsManager = new \Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
//controller or action doesn't exist
if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
return false;
}
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
return false;
}
});
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
};
$di['view'] = function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('../../common/layout_frontend/');
return $view;
};
}
示例6: setView
private function setView($manager, $theme)
{
/* ==================================================
* ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
* Setting up the view component
* ================================================== */
$manager->set('view', function () use($theme) {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
/* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
$view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $theme));
/* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
$view->setTemplateAfter('layouts/' . $this->layoutName);
/* เลือกไฟล์ layout เริ่มต้น*/
/* สร้างโฟล์เดอร์เก็บไฟล์ cache */
$cacheDir = sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName);
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$view->registerEngines(array('.phtml' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName), 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
}
示例7: setView
private function setView()
{
$view = new View();
$view->setViewsDir($this->config->application->viewsDir);
$view->setLayoutsDir('layouts/');
$view->setLayout('index');
$view->registerEngines(['.volt' => $this->setVolt($view), '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
return $view;
}
示例8: registerServices
/**
* Register specific services for the module
*/
public function registerServices(\Phalcon\DiInterface $dependencyInjector)
{
/**
* Read configuration
*/
$config = (require_once MODULES_DIR . $this->module_name . DS . "config" . DS . "config.php");
//Registering a dispatcher
$dependencyInjector->set('dispatcher', function () {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Attach a event listener to the dispatcher
$eventManager = new \Phalcon\Events\Manager();
//$eventManager->attach('dispatch', new \Acl($this->module_name));
$dispatcher->setEventsManager($eventManager);
$dispatcher->setDefaultNamespace("Mod\\ModMan\\Controllers\\");
return $dispatcher;
});
/**
* Setting up the view component
*/
$dependencyInjector->set('view', function () use($config) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir($config->module->viewsDir);
$view->setViewsDir(MODULES_DIR . $this->module_name . DS . 'views' . DS);
$view->setLayoutsDir(MODULES_DIR . $this->module_name . DS . 'layouts' . DS);
//$view->setTemplateAfter('index');
$view->registerEngines(array('.volt' => function ($view, $di) {
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(array('compiledPath' => MODULES_DIR . $this->module_name . DS . 'views' . DS . '_compiled' . DS, 'stat' => true, 'compileAlways' => true));
return $volt;
}));
return $view;
});
/**
* Database connection is created based in the parameters defined in the configuration file
* http://stackoverflow.com/questions/22197678/how-to-connect-multiple-database-in-phalcon-framework
*/
$dependencyInjector->set('db', function () use($config) {
return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
});
}
示例9: registerServices
/**
*
* @param \Phalcon\DI $di
*/
public function registerServices($di)
{
Admin::instance();
require __DIR__ . '/../../../../phad/phad.php';
$di['phadConfig'] = function () {
$config = (require __DIR__ . '/../../../../phad-config.php');
return new Config($config);
};
$di['view'] = function () {
$view = new ViewEngine();
$view->setViewsDir(__DIR__ . '/Views/');
$view->setLayoutsDir('Layouts/');
$view->setPartialsDir('Partials/');
return $view;
};
$di['viewSimple'] = function () {
$view = new Simple();
$view->setViewsDir(__DIR__ . '/Views/');
return $view;
};
$di['flashSession'] = function () {
$flashClasses = ['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'];
return new FlashSession($flashClasses);
};
$di['session'] = function () {
$session = new Session();
$session->start();
return $session;
};
$di['phadAuth'] = function () {
return new Auth();
};
$di['assets'] = function () use($di) {
$options = ['sourceBasePath' => __DIR__ . '/Assets/', 'targetBasePath' => __DIR__ . '/../../../../public/backend-assets/'];
$assets = new AssetsManager($options);
$assets->collection('backend_css')->setTargetPath('final.css')->setTargetUri('backend-assets/final.css')->addCss('bootstrap/css/bootstrap.min.css')->addCss('css/styles.css')->join(true)->addFilter(new AssetsNullFilter());
$assets->collection('backend_js')->setTargetPath('final.js')->setTargetUri('backend-assets/final.js')->addJs('bootstrap/js/bootstrap.min.js')->addJs('js/custom.js')->join(true)->addFilter(new AssetsNullFilter());
return $assets;
};
}
示例10: registerViewService
/**
* @param \Phalcon\DI\FactoryDefault $di
*/
protected function registerViewService($di)
{
/**
* Setting up the view component
*/
$di['view'] = function () use($di) {
/*
* Obtengo el nombre del modulo para poder obner el archivo de configuracion
*/
$module = $this->name;
$this->layout_dir = '../../../../public/layouts/' . $di->get('modules')->{$module}->layout . '/';
$view = new View();
$view->setViewsDir($this->path . $this->view_dir);
$view->setLayoutsDir($this->layout_dir);
$view->setTemplateAfter($this->template);
$view->setVar('project-setting', $di->get('config')->project->toArray());
/*
* Registra Constantes de Modulo
*/
$view->setVar('module-setting', $di->get('modules')->{$module}->toArray());
// Set the engine
$view->registerEngines(array(".mustache" => function ($view, DI $di) {
$module = $this->name;
$partial_url = '../public/layouts/' . $di->get('modules')->{$module}->layout . '/partials';
$partial_loader = new Mustache_Loader_FilesystemLoader($partial_url);
$config = $di->get('config')->cache->frontend;
if ($config->active == 0) {
$options = array('partials_loader' => $partial_loader);
} else {
$options = array('cache' => '/var/www/var/cache/elephant', 'cache_file_mode' => $config->mode, 'partials_loader' => $partial_loader, 'strict_callables' => $config->callables);
}
$mustache = new Mustache($view, $di, $options);
return $mustache;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
};
}
示例11: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$config = new Ini(APP_PATH . "/apps/teacher/config/config.ini");
/**
* Setting up the view component
*/
$di['view'] = function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
// set layout
$view->setLayoutsDir('../../../layouts/');
$view->setTemplateAfter('main');
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
};
}
示例12: function
/**
* If the configuration specify the use of metadata adapter use it or use memory otherwise
*/
$di->set('modelsMetadata', function () {
return new MetaDataAdapter();
});
/**
* Start the session the first time some component request the session service
*/
$di->set('session', function () {
$session = new SessionAdapter();
$session->start();
return $session;
});
$di->set('view', function () use($config, $di) {
$view = new View();
$router = $di->getShared('router');
/*
* @todo 给layouts等目录统一变量
* */
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('/../../../layouts/');
// 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
$view->setLayout('adminCommon');
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
}, true);
示例13: Dispatcher
$eventsManager = $manager->getShared('eventsManager');
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
/* ==================================================
* ตั้งค่าการเชื่อมต่อฐานข้อมูล
* ================================================== */
$manager->set('db', function () {
return new DbAdapter(array('host' => $this->config->database->host, 'username' => $this->config->database->username, 'password' => $this->config->database->password, 'dbname' => $this->config->database->dbname, 'options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->config->database->charset)));
});
$manager->set('view', function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
/* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
$view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $this->config->theme->themeDefault));
/* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
$view->setTemplateAfter('layouts/' . $this->config->theme->layoutDefault);
/* เลือกไฟล์ layout เริ่มต้น*/
/* สร้างโฟล์เดอร์เก็บไฟล์ cache */
$cacheDir = sprintf('%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir);
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$view->registerEngines(array('.phtml' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => sprintf('%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir), 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
示例14: initView
/**
*
* @param type $options
*/
protected function initView($options = [])
{
$config = $this->_di->get('config');
$di = $this->_di;
if (!file_exists($config->volt->path)) {
mkdir($config->volt->path, 0777, true);
}
$this->_di->setShared('volt', function ($view, $di) use($config) {
$volt = new Volt($view, $di);
$volt->setOptions(['compiledPath' => $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'compileAlways' => (bool) $config->volt->compileAlways, 'stat' => (bool) $config->volt->stat]);
$compiler = $volt->getCompiler();
$compiler->addFunction('is_a', 'is_a');
return $volt;
});
$this->_di->setShared('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setMainView('index');
$view->setLayoutsDir('layouts/');
$view->setPartialsDir('partials/');
$view->registerEngines(['.volt' => 'volt', '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
return $view;
});
}
示例15: function
});
/**
* The URL component is used to generate all kinds of URLs in the application
*/
$di->setShared('url', function () use($config) {
$url = new UrlResolver();
$url->setBaseUri($config->application->baseUri);
return $url;
});
/**
* Setting up the view component
*/
$di->setShared('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setLayoutsDir('../../common/layouts/');
$view->setTemplateAfter('main');
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'stat' => true, 'compileAlways' => true));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
});
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di->setShared('db', function () use($config) {
$dbConfig = $config->database->toArray();
$adapter = $dbConfig['adapter'];
unset($dbConfig['adapter']);