本文整理匯總了PHP中Phalcon\Mvc\View::setRenderLevel方法的典型用法代碼示例。如果您正苦於以下問題:PHP View::setRenderLevel方法的具體用法?PHP View::setRenderLevel怎麽用?PHP View::setRenderLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setRenderLevel方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testStandardRender
public function testStandardRender()
{
$view = new View();
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$this->assertEquals($view->getViewsDir(), 'unit-tests/views/');
//Standard Render
$view->start();
$view->render('test2', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>here</html>' . PHP_EOL);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
//Variables
$view->setParamToView('a_cool_var', 'le-this');
$view->start();
$view->render('test3', 'another');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lol<p>le-this</p></html>' . PHP_EOL);
//Templates
$view->setTemplateAfter('test');
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
$view->cleanTemplateAfter();
//Render Levels
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'lolhere');
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'here');
//Pick View
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->start();
$view->pick('test3/yup');
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lolyup</html>' . PHP_EOL);
//No Render
$view->setRenderLevel(View::LEVEL_NO_RENDER);
$view->start();
$view->pick('test3/yup');
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '');
}
示例2: register
public function register()
{
$view = new PhalconView();
$config = $this->getConfig('view');
$configDefault = $this->getConfig('view.default');
// if no engine setted or default == 'null' then
// set no render level of view
if ('null' == $configDefault) {
$view::LEVEL_NO_RENDER;
return $view;
}
$view->setViewsDir($this->getConfig('view.path'));
$view->setRenderLevel(PhalconView::LEVEL_LAYOUT);
$di = $this->getDI();
$default = 'register' . ucfirst($configDefault);
$this->{$default}($view, $di, $config);
return $view;
}
示例3: testGetActiveRenderPath
/**
* Tests the View::getActiveRenderPath
*
* @issue 12139
* @author Serghei Iakovlev <serghei@phalconphp.com>
* @since 2014-08-14
*/
public function testGetActiveRenderPath()
{
$this->specify('The View::getActiveRenderPath returns unexpected result', function () {
$view = new View();
$eventsManager = new Manager();
$eventsManager->attach('view', new ViewAfterRenderListener());
$view->setViewsDir(PATH_DATA . 'views');
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->setEventsManager($eventsManager);
expect($view->getActiveRenderPath())->equals('');
$view->start();
$view->render('test15', 'index');
$view->finish();
$view->getContent();
expect($view->getActiveRenderPath())->equals(PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml');
$view->setViewsDir([PATH_DATA . 'views', PATH_DATA . 'views2']);
expect($view->getActiveRenderPath())->equals([PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml']);
});
}
示例4: function
/**
* The Dispatcher component
*/
$di->setShared('dispatcher', function () use($di) {
$eventsManager = $di->getShared('eventsManager');
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
/**
* Setting up the view component
*/
$di->set('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'compileAlways' => true));
//add filter functions
$compiler = $volt->getCompiler();
$compiler->addFilter('uniform_time', function ($resolvedArgs, $exprAgs) {
return "date('Y-m-d H:i:s', strtotime(" . $resolvedArgs . "))";
});
$compiler->addFilter('number_format', function ($resolveArgs, $exprAgs) {
return 'number_format(' . $resolveArgs . ')';
});
$compiler->addFilter('urlencode', function ($resolveArgs, $exprAgs) {
return 'urlencode(' . $resolveArgs . ')';
});
return $volt;
示例5: renderContent
/**
* render the content of an existing view : $controller/$action and set the response to the modal content
* @param View $view
* @param string $controller a Phalcon controller
* @param string $action a Phalcon action
* @param $params The parameters to pass to the view
*/
public function renderContent($view, $controller, $action, $params = NULL)
{
$template = $view->getRender($controller, $action, $params, function ($view) {
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
});
$this->content = $template;
}
示例6: registerServices
//.........這裏部分代碼省略.........
$di->getVersionLoader()->load();
});
$oApiDispatcherEventsManager->attach('dispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
/**
* @type \DiCustom $di
*/
$di = Di::getDefault();
$oLogger = $di->getFileLogger();
// $oRouter = $di->getRouter();
//
// $arParams = $oRouter->getParams();
//
// $oLogger->debug(__CLASS__ . ': ' . $oEvent->getType() . ': trying to dispatch: from router: '
// . ' module: ' . $oRouter->getModuleName()
// . ' media: ' . $arParams['media']
// . ' version: v' . $arParams['major'] . '_' . $arParams['minor']
// . ' controller: ' . $oRouter->getControllerName()
// . ' action: ' . $oRouter->getActionName()
// );
$arParams = $oDispatcher->getParams();
$oLogger->debug(__CLASS__ . ': ' . $oEvent->getType() . ': trying to dispatch: from dispatcher: ' . ' module: ' . $oDispatcher->getModuleName() . ' media: ' . $arParams['media'] . ' version: v' . $arParams['major'] . '_' . $arParams['minor'] . ' controller: ' . $oDispatcher->getControllerName() . ' action: ' . $oDispatcher->getActionName());
// $oLogger->debug(__CLASS__ . ': ' . $oEvent->getType());
});
$oDispatcher->setEventsManager($oApiDispatcherEventsManager);
$di->setShared('dispatcher', $oDispatcher);
// $di->set('dispatcher', function() use($di){
// $dispatcher = new Dispatcher();
// $oApiDispatcherEventsManager = new Manager();
// $oLogger = $di->getFileLogger();
// $oRouter = $di->getRouter();
// $oRequest = $di->getRequest();
//
// $oLogger->debug('api module ' . __FUNCTION__ . ': setting up dispatcher');
//
// $oApiDispatcherEventsManager->attach('dispatch', function(Event $event, Dispatcher $dispatcher, $data) use($oLogger, $oRouter, $oRequest){
//
// if($event->getType() == 'beforeDispatchLoop'){
//
// $arRoutes = $oRouter->getRoutes();
//
// foreach ($arRoutes as $oRoute) {
// $oRoute->beforeMatch(function($uri, $route) use ($oLogger){
// $oLogger->debug('__ api module dispatcher route beforeMatch: ' . $uri . $route);
//
// });
// $oLogger->debug('api module dispatcher: ' . $event->getType() . ': route registered: ' . $oRoute->getCompiledPattern());
//
// $regPattern = $oRoute->getCompiledPattern();
//
// $strUri = $oRequest->getURI();
//
// if(preg_match($regPattern, $strUri)){
// $oLogger->debug('"' . $strUri . '" matched ' . $regPattern);
// }else{
// $oLogger->debug('"' . $strUri . '" mismatched ' . $regPattern);
// }
//
// }
//
// }
//
// $oLogger->debug('api dispatcher: ' . $event->getType() . ': route matched: ' . print_r($oRouter->getMatchedRoute(), true));
// $oLogger->debug('api dispatcher: ' . $event->getType()
// . ' module "' . $oRouter->getModuleName()
// . '" controller: "' . $oRouter->getControllerName()
// . '" action: "' . $oRouter->getActionName() . '"'
// );
// });
//
// $dispatcher->setEventsManager($oApiDispatcherEventsManager);
// $dispatcher->setDefaultNamespace('App\Modules\Api\Web');
// return $dispatcher;
// });
//
//
//
// $oConfig = new Config(array(
// 'application' => array(
// 'viewsDir' => __DIR__ . '/views',
// 'cacheDir' => __DIR__ . '/../../../var/cache/regular'
// ),
// ));
//
// $di->get('config')->merge($oConfig);
/**
* Setting up the view component
*/
$di->set('view', function () use($oLogger) {
$oView = new View();
$oView->setRenderLevel(View::LEVEL_NO_RENDER);
$oView->disable();
$oLogger->debug('view: render level set to disabled');
//Disable several levels
// $view->disableLevel(array(
// View::LEVEL_LAYOUT => true,
// View::LEVEL_MAIN_LAYOUT => true
// ));
return $oView;
}, true);
}
示例7: testIssue907
public function testIssue907()
{
$view = new View();
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$listener = new \ViewAfterRenderListener();
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('view', $listener);
$view->setEventsManager($eventsManager);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
$this->assertEquals('1,3,6', $listener->getLevels());
$listener->reset();
//Templates
$view->setTemplateAfter('test');
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
$this->assertEquals('1,3,5,6', $listener->getLevels());
$listener->reset();
$view->cleanTemplateAfter();
//Render Levels
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
$this->assertEquals('1,3,6', $listener->getLevels());
$listener->reset();
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'lolhere');
$this->assertEquals('1,3', $listener->getLevels());
$listener->reset();
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->start();
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'here');
$this->assertEquals('1', $listener->getLevels());
$listener->reset();
}
示例8: testVoltEngine
public function testVoltEngine()
{
$this->specify("Volt engine doesn't work as expected", function () {
@unlink(PATH_DATA . 'views/layouts/test10.volt.php');
@unlink(PATH_DATA . 'views/test10/index.volt.php');
@unlink(PATH_DATA . 'views/test10/other.volt.php');
$di = new Di();
$view = new View();
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views/');
$view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
$view->setParamToView('song', 'Rock n roll');
$view->start();
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->render('test10', 'index');
$view->finish();
expect($view->getContent())->equals('Hello Rock n roll!');
$view->setParamToView('some_eval', true);
$view->start();
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->render('test10', 'index');
$view->finish();
expect($view->getContent())->equals('Clearly, the song is: Hello Rock n roll!.' . PHP_EOL);
//Refreshing generated view
file_put_contents(PATH_DATA . 'views/test10/other.volt', '{{song}} {{song}}');
$view->setParamToView('song', 'Le Song');
$view->start();
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->render('test10', 'other');
$view->finish();
expect($view->getContent())->equals('Le Song Le Song');
$view->start();
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->render('test10', 'other');
$view->finish();
expect($view->getContent())->equals('Clearly, the song is: Le Song Le Song.' . PHP_EOL);
//Change the view
file_put_contents(PATH_DATA . 'views/test10/other.volt', 'Two songs: {{song}} {{song}}');
$view->start();
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->render('test10', 'other');
$view->finish();
expect($view->getContent())->equals('Clearly, the song is: Two songs: Le Song Le Song.' . PHP_EOL);
});
}
示例9: testStandardRender
/**
* Tests View::render
*
* @author Andres Gutierrez <andres@phalconphp.com>
* @since 2012-03-05
*/
public function testStandardRender()
{
$this->specify('The View component does not work as expected', function () {
$view = new View();
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->start();
$view->render('test2', 'index');
$view->finish();
expect($view->getContent())->equals("<html>We are here</html>\n");
$view->start();
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals("<html>lolhere</html>\n");
$view->setParamToView('a_cool_var', 'le-this');
$view->start();
$view->render('test3', 'another');
$view->finish();
expect($view->getContent())->equals("<html>lol<p>le-this</p></html>\n");
$view->setTemplateAfter('test');
$view->start();
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals("<html>zuplolhere</html>\n");
$view->cleanTemplateAfter();
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals("<html>lolhere</html>\n");
$view->setRenderLevel(View::LEVEL_LAYOUT);
$view->start();
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals('lolhere');
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->start();
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals('here');
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->start();
$view->pick('test3/yup');
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals("<html>lolyup</html>\n");
$view->setRenderLevel(View::LEVEL_NO_RENDER);
$view->start();
$view->pick('test3/yup');
$view->render('test3', 'other');
$view->finish();
expect($view->getContent())->equals('');
});
}
示例10: testVoltEngine
public function testVoltEngine()
{
@unlink('unit-tests/views/layouts/test10.volt.php');
@unlink('unit-tests/views/test10/index.volt.php');
@unlink('unit-tests/views/test10/other.volt.php');
$di = new Phalcon\DI();
$view = new Phalcon\Mvc\View();
$view->setDI($di);
$view->setViewsDir('unit-tests/views/');
$view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
$view->setParamToView('song', 'Rock n roll');
$view->start();
$view->setRenderLevel(Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->render('test10', 'index');
$view->finish();
$this->assertEquals($view->getContent(), 'Hello Rock n roll!');
$view->setParamToView('some_eval', true);
$view->start();
$view->setRenderLevel(Phalcon\Mvc\View::LEVEL_LAYOUT);
$view->render('test10', 'index');
$view->finish();
$this->assertEquals($view->getContent(), 'Clearly, the song is: Hello Rock n roll!.' . PHP_EOL);
//Refreshing generated view
file_put_contents('unit-tests/views/test10/other.volt', '{{song}} {{song}}');
$view->setParamToView('song', 'Le Song');
$view->start();
$view->setRenderLevel(Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->render('test10', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'Le Song Le Song');
$view->start();
$view->setRenderLevel(Phalcon\Mvc\View::LEVEL_LAYOUT);
$view->render('test10', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'Clearly, the song is: Le Song Le Song.' . PHP_EOL);
//Change the view
file_put_contents('unit-tests/views/test10/other.volt', 'Two songs: {{song}} {{song}}');
$view->start();
$view->setRenderLevel(Phalcon\Mvc\View::LEVEL_LAYOUT);
$view->render('test10', 'other');
$view->finish();
$this->assertEquals($view->getContent(), 'Clearly, the song is: Two songs: Le Song Le Song.' . PHP_EOL);
}
示例11: _renderJson
protected function _renderJson(View $view)
{
$this->getResponse()->setContentType('application/json')->setJsonContent($view->getParamsToView())->send();
$view->setRenderLevel(View::LEVEL_NO_RENDER);
}