本文整理汇总了PHP中Cake\View\View类的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
/**
* Checks whether the response was cached and set the body accordingly.
*
* @param \Cake\Event\Event $event containing the request and response object
* @return \Cake\Network\Response with cached content if found, null otherwise
*/
public function beforeDispatch(Event $event)
{
if (Configure::read('Cache.check') !== true) {
return;
}
$path = $event->data['request']->here();
if ($path === '/') {
$path = 'home';
}
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views/' . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views/' . $path . '_index.php';
}
if (file_exists($filename)) {
$controller = null;
$view = new View($controller);
$view->response = $event->data['response'];
$result = $view->renderCache($filename, microtime(true));
if ($result !== false) {
$event->stopPropagation();
$event->data['response']->body($result);
return $event->data['response'];
}
}
}
示例2: _getView
/**
* Prepares a View instance with which the given view file
* will be rendered.
*
* @return View
*/
protected function _getView()
{
$view = new View();
foreach ($this->config('helpers') as $helper) {
$view->loadHelper($helper);
}
return $view;
}
示例3: testIsAuthorized
/**
* Test isAuthorized
*
* @return void
*/
public function testIsAuthorized()
{
$view = new View();
$eventManagerMock = $this->getMockBuilder('Cake\\Event\\EventManager')->setMethods(['dispatch'])->getMock();
$view->eventManager($eventManagerMock);
$this->AuthLink = new AuthLinkHelper($view);
$result = new Event('dispatch-result');
$result->result = true;
$eventManagerMock->expects($this->once())->method('dispatch')->will($this->returnValue($result));
$result = $this->AuthLink->isAuthorized(['controller' => 'MyController', 'action' => 'myAction']);
$this->assertTrue($result);
}
示例4: testLogWriting
/**
* Tests the log write method
*
* @return void
*/
public function testLogWriting()
{
$View = new View();
$countBefore = $this->Logs->find()->count();
$View->log('x');
$View->log('warning', LOG_WARNING);
Log::write(LOG_ERR, 'y');
Log::write(LOG_INFO, 'z');
$countAfter = $this->Logs->find()->count();
$this->assertSame($countBefore + 8, $countAfter);
// should be 4 (but for some reason everything is added twice
}
示例5: render
/**
* Render the cell.
*
* @param string|null $template Custom template name to render. If not provided (null), the last
* value will be used. This value is automatically set by `CellTrait::cell()`.
* @return string The rendered cell.
* @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering.
*/
public function render($template = null)
{
if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false) {
$template = Inflector::underscore($template);
}
if ($template === null) {
$template = $this->template;
}
$builder = $this->viewBuilder();
$builder->layout(false);
$builder->template($template);
$cache = [];
if ($this->_cache) {
$cache = $this->_cacheConfig($template);
}
$this->View = $this->createView();
$render = function () use($template) {
$className = substr(strrchr(get_class($this), "\\"), 1);
$name = substr($className, 0, -4);
$this->View->templatePath('Cell' . DS . $name);
try {
return $this->View->render($template);
} catch (MissingTemplateException $e) {
throw new MissingCellViewException(['file' => $template, 'name' => $name]);
}
};
if ($cache) {
return $this->View->cache(function () use($render) {
echo $render();
}, $cache);
}
return $render();
}
示例6: get_for_parent
public function get_for_parent($parent, $page)
{
$comments = $this->Comments->find()->where(['Comments.object_id' => $parent])->limit(__MAX_COMMENTS_LISTED)->page($page)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
// Reorder the Comments by creation order
// (even though we got them by descending order)
$collection = new Collection($comments);
$comments = $collection->sortBy('Comment.created');
$view = new View($this->request, $this->response, null);
$view->layout = 'ajax';
// layout to use or false to disable
$view->set('comments', $comments->toArray());
$data['html'] = $view->render('Social.Comments/get_for_parent');
$this->layout = 'ajax';
$this->set('data', $data);
$this->render('/Shared/json/data');
}
示例7: testRoles
/**
* @return void
*/
public function testRoles()
{
$this->AuthUserHelper->config('multiRole', true);
$user = ['id' => '1', 'Roles' => ['1', '2']];
$this->View->set('_authUser', $user);
$this->assertSame(['user' => '1', 'moderator' => '2'], $this->AuthUserHelper->roles());
}
示例8: __construct
/**
* Constructor
*
* @param \Cake\Network\Request $request The request object.
* @param \Cake\Network\Response $response The response object.
* @param \Cake\Event\EventManager $eventManager Event manager object.
* @param array $viewOptions View options.
*/
public function __construct(Request $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = [])
{
parent::__construct($request, $response, $eventManager, $viewOptions);
if ($response && $response instanceof Response) {
$response->type('ajax');
}
}
示例9: formatter
/**
* Renders the given custom field.
*
* @param \Cake\View\View $view Instance of view class
* @param \Field\Model\Entity\Field $field The field to be rendered
* @return string HTML code
*/
public static function formatter($view, $field)
{
switch ($field->viewModeSettings['formatter']) {
case 'link':
$out = $view->element('Field.FileField/display_link', compact('field'));
break;
case 'table':
$out = $view->element('Field.FileField/display_table', compact('field'));
break;
case 'url':
default:
$out = $view->element('Field.FileField/display_url', compact('field'));
break;
}
return $out;
}
示例10: __construct
public function __construct(Request $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = [])
{
parent::__construct($request, $response, $eventManager, $viewOptions);
$this->_serviceProvider = new ServiceProvider(Configure::read('App.paths.templates'), CACHE . 'bladeView');
$this->loadBlade();
$this->_loadHelpers();
$this->loadExtensions();
}
示例11: initialize
/**
* Initialization hook method.
*
* For e.g. use this method to load a helper for all views:
* `$this->loadHelper('Html');`
*
* @return void
*/
public function initialize()
{
parent::initialize();
// $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
// $this->loadHelper('Form', ['className' => 'BootstrapUI.Form']);
// $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']);
// $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']);
$this->eventManager()->dispatch(new Event('Spider.SpiderAppView.initialize', $this));
}
示例12: _getViewFileName
/**
* Returns filename of given action's template file (.ctp) as a string.
* CamelCased action names will be under_scored! This means that you can have
* LongActionNames that refer to long_action_names.ctp views.
*
* @param string $name Controller action to find template filename for
* @return string Template filename
* @throws \Cake\View\Exception\MissingViewException when a view file could not be found.
*/
protected function _getViewFileName($name = null)
{
try {
$result = parent::_getViewFileName($name);
} catch (MissingViewException $e) {
throw new Exception\MissingDashboardException($e->getMessage());
}
return $result;
}
示例13: getFunctions
/**
* Get declared functions.
*
* @return \Twig_SimpleFunction[]
*/
public function getFunctions()
{
return [new \Twig_SimpleFunction('elementExists', function ($name) {
return $this->view->elementExists($name);
}), new \Twig_SimpleFunction('getVars', function () {
return $this->view->getVars();
}), new \Twig_SimpleFunction('get', function ($var, $default = null) {
return $this->view->get($var, $default);
})];
}
示例14: initialize
/**
* Initialization hook method.
*
* For e.g. use this method to load a helper for all views:
* `$this->loadHelper('Html');`
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadHelper('Html');
$this->loadHelper('Form');
$this->loadHelper('MyUtils');
}
示例15: initialize
/**
* Initialization hook method.
*
* For e.g. use this method to load a helper for all views:
* `$this->loadHelper('Html');`
*
* @return void
*/
public function initialize()
{
parent::initialize();
// $this->loadHelper('Html');
// $this->loadHelper('Form');
// $this->loadHelper('Flash');
}