本文整理汇总了PHP中Phalcon\Mvc\View::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getContent方法的具体用法?PHP View::getContent怎么用?PHP View::getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::getContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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']);
});
}
示例3: testPartials
public function testPartials()
{
$view = new Phalcon\Mvc\View();
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$this->assertEquals($view->getViewsDir(), 'unit-tests/views/');
$view->setParamToView('cool_var', 'le-this');
$view->start();
$view->render('test5', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Hey, this is a partial, also le-this</html>' . PHP_EOL);
$view->start();
$view->render('test9', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Hey, this is a partial, also le-this<br />Hey, this is a second partial, also le-this</html>' . PHP_EOL);
}
示例4: 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();
}
示例5: testViewOptions
public function testViewOptions()
{
$config = array('cache' => array('service' => 'otherCache'));
$date = date("r");
$content = '<html>' . $date . '</html>' . PHP_EOL;
$di = $this->_getDi('otherCache');
$view = new View($config);
$view->setDI($di);
$view->setViewsDir('unit-tests/views/');
$view->setVar("date", $date);
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
$this->assertEquals($view->getContent(), $content);
$view->reset();
sleep(1);
$view->setVar("date", date("r"));
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
$this->assertEquals($view->getContent(), $content);
}
示例6: testVoltMacrosIssue11771
public function testVoltMacrosIssue11771()
{
$this->specify("Volt macros can't accept objects", function () {
$this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
Di::reset();
$view = new View();
$di = new Di();
$di->set('escaper', function () {
return new Escaper();
});
$di->set('tag', function () {
return new Tag();
});
$di->set('url', function () {
return (new Url())->setBaseUri('/');
});
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
return new Volt($view, $di);
}));
$object = new \stdClass();
$object->foo = "bar";
$object->baz = "buz";
$object->pi = 3.14;
$object->ary = ["some array"];
$object->obj = clone $object;
$view->setVar('object', $object);
$view->start();
$view->render('macro', 'list');
$view->finish();
ob_start();
var_dump($object);
$actual = ob_get_clean();
// Trim xdebug first line (file path)
$actual = substr($actual, strpos($actual, 'class'));
$expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
expect($actual)->equals($expected);
$form = new Form();
$form->add(new Password('password'));
$view->setVar('formLogin', $form);
$view->start();
$view->render('macro', 'form_row');
$view->finish();
$actual = <<<FORM
<div class="form-group">
<label class="col-sm-2 control-label" for="password">password:</label>
<div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
expect($actual)->equals($view->getContent());
$this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
});
}
示例7: afterRender
/**
* @param Event $event
* @param View $view
* @param mixed $viewFile
*/
public function afterRender($event, $view, $viewFile)
{
$this->endTime = microtime(true);
$content = $view->getContent();
$scripts = "</head>";
$content = str_replace("</head>", $scripts, $content);
$rendered = $this->renderToolbar();
$rendered .= "</body>";
$content = str_replace("</body>", $rendered, $content);
$view->setContent($content);
}
示例8: testVoltEngineBuiltInFunctions
public function testVoltEngineBuiltInFunctions()
{
@unlink('unit-tests/views/test11/index.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->setVar('arr', array(1, 2, 3, 4));
$view->setVar('obj', new SomeObject(array(1, 2, 3, 4)));
$view->setVar('str', 'hello');
$view->setVar('no_str', 1234);
$view->start();
$view->render('test11', 'index');
$view->finish();
$this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
}
示例9: testViewOptions
public function testViewOptions()
{
$this->specify("Views are not cached properly when passing options to the constructor", function () {
$this->_clearCache();
$config = array('cache' => array('service' => 'otherCache'));
$date = date("r");
$content = '<html>' . $date . '</html>' . PHP_EOL;
$di = $this->_getDi('otherCache');
$view = new View($config);
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->setVar("date", $date);
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
expect($view->getContent())->equals($content);
$view->reset();
sleep(1);
$view->setVar("date", date("r"));
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
expect($view->getContent())->equals($content);
});
}