本文整理汇总了PHP中Context::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::setContent方法的具体用法?PHP Context::setContent怎么用?PHP Context::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context::setContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPlacementPrepend
public function testPlacementPrepend()
{
$context = new Context();
$context->add('content', array('name' => 'one', 'placement' => 'prepend'));
$context->add('content', array('name' => 'two'));
$context->setContent('one', 'outer');
$context->setContent('two', 'inner');
$expected = 'outerinner';
$actual = $context->render();
$this->assertEquals($expected, $actual);
}
示例2: createContext
/**
* Creates a sub context of the given name
* @param string $name the context name
* @param string $id the id of the new context
* @return Context The created context
*/
public function createContext($name, $id = null)
{
$context = new Context($name, $id);
$id = $context->id();
// add selectors
foreach ($this->_selectors as $key => $selector) {
$parts = explode(' ', $key);
// handle nested selectors
$first = array_shift($parts);
if (count($parts) > 0 && $context->applies($first)) {
$key = implode(' ', $parts);
}
$context->_selectors[$key] = $selector;
}
// add tags and ids
$context->_tags = $this->_tags;
$context->_ids = $this->_ids;
// add content
$context->_content = $this->_content;
$content = $this->getContent();
if (is_array($content) && isset($content[$id])) {
$content = $content[$id];
}
$context->setContent($name, $content);
self::$_log[] = '[Context] Creating context ' . $name . ' with id ' . $id;
return $context;
}
示例3: testTableWithIds
public function testTableWithIds()
{
$context = new Context('table');
$context->add('table');
$context->add('contexts', 'row');
$context->select('row')->add('tr')->add('contexts', 'column');
$context->select('column')->add('td')->add('content');
$context->ids('column', 'name,email');
$data = array(array('id' => 23, 'name' => 'Peter', 'email' => 'peter@alps.ch'), array('id' => 17, 'name' => 'Heidi', 'email' => 'heidi@alps.ch'));
$context->setContent($data);
$expected = '<table><tr><td>Peter</td><td>peter@alps.ch</td></tr><tr><td>Heidi</td><td>heidi@alps.ch</td></tr></table>';
$actual = $context->render();
$this->assertEquals($expected, $actual);
}
示例4: testSettingEmptyContentIfParamMatchesName
public function testSettingEmptyContentIfParamMatchesName()
{
$context = new Context('test');
$content = array();
$context->setContent('test', $content);
$actual = $context->getContent('test');
$this->assertEquals(array(), $actual);
}
示例5: Context
$ctx = new Context($_GET, $_POST, $_SERVER);
if ($ctx->isFile()) {
readfile('.' . $ctx->getPath());
exit;
} else {
if (preg_match('/\\.php$/', $ctx->getPath())) {
include '.' . $ctx->getPath();
exit;
} else {
ob_start();
try {
$r = $ctx->loadComponent();
} catch (ContextException $ce) {
if ($ce->getCode() == 404) {
$ctx->setHTTPStatus(404, "Not found");
$ctx->setContent($ce->getMessage());
} else {
$ctx->setHTTPStatus(500, "Internal error in PHP software");
$ctx->setContent($ce->getMessage());
}
}
$output = ob_get_clean();
if (!empty($output)) {
$ctx->appendContent($output);
}
if (!empty($r)) {
$ctx->appendContent($r);
}
}
}
$ctx->flushHeaders();