本文整理汇总了PHP中Phalcon\Mvc\View::setParamToView方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setParamToView方法的具体用法?PHP View::setParamToView怎么用?PHP View::setParamToView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setParamToView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: testPartials
public function testPartials()
{
$view = new View();
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$view->setParamToView('cool_var', 'le-this');
// Single partial
$view->start();
$view->render('test5', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Hey, this is a partial, also le-this</html>' . PHP_EOL);
// Multiple partials
$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);
// A partial within other partial
$view->start();
$view->render('test5', 'subpartial');
$view->finish();
$this->assertEquals('<html>Including Hey, this is a partial, also le-this</html>' . PHP_EOL, $view->getContent());
// Single partial in overridden main view
$view->setMainView('html5');
$view->start();
$view->render('test5', 'index');
$view->finish();
$this->assertEquals('<!DOCTYPE html><html>Hey, this is a partial, also le-this</html>' . PHP_EOL, $view->getContent());
}
示例4: 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);
});
}
示例5: testRenderingWithPartials
/**
* Tests rendering with partials
*
* @author Andres Gutierrez <andres@phalconphp.com>
* @since 2012-05-28
*/
public function testRenderingWithPartials()
{
$this->specify('The rendering with partials does not work as expected', function () {
$view = new View();
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->setParamToView('cool_var', 'le-this');
$view->start();
$view->render('test5', 'index');
$view->finish();
expect($view->getContent())->equals("<html>Hey, this is a partial, also le-this</html>\n");
$view->start();
$view->render('test9', 'index');
$view->finish();
expect($view->getContent())->equals("<html>Hey, this is a partial, also le-this<br />Hey, this is a second partial, also le-this</html>\n");
$view->start();
$view->render('test5', 'subpartial');
$view->finish();
expect($view->getContent())->equals("<html>Including Hey, this is a partial, also le-this</html>\n");
$view->setMainView('html5');
$view->start();
$view->render('test5', 'index');
$view->finish();
expect($view->getContent())->equals("<!DOCTYPE html><html>Hey, this is a partial, also le-this</html>\n");
expect($view->getPartial('partials/_partial1', ['cool_var' => 'le-this']))->equals('Hey, this is a partial, also le-this');
});
}
示例6: 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);
}