public function testDisplayFor() { $View = new View(); $View->Session = $this->getMock('SessionHelper', array('read')); $View->request = $this->getMock('CakeRequest', array('_readInput')); $View->request->addParams(array('models' => array('Article' => array()), 'controller' => 'articles', 'action' => 'view')); $Ratings = $this->getMock('RatingsHelper', array('getRandomId'), array($View)); $Ratings->Session = $View->Session; $Ratings->setModels(array('Article' => 'Content.Article')); $Ratings->expects($this->once())->method('getRandomId')->will($this->returnValue(666)); $data = array('Article' => array('id' => 1), 'RatingSummary' => array('total_rating' => 3.5, 'total_votes' => 42)); $result_html = $Ratings->display_for($data); $result_script = $View->fetch('script_execute'); $expected = array('tag' => 'div', 'attributes' => array('class' => 'rating'), 'child' => array('tag' => 'div', 'id' => 'rating-666', 'attributes' => array('class' => 'rateit bigstars')), 'children' => array('count' => 2)); $this->assertTag($expected, $result_html); $expected = array('tag' => 'span', 'id' => 'message-666', 'attributes' => array('class' => 'rating-message')); $this->assertTag($expected, $result_html); $expected = array('tag' => 'span', 'id' => 'values-666', 'attributes' => array('class' => 'rating-values'), 'child' => array('tag' => 'span', 'content' => '3.50', 'attributes' => array('class' => 'rating')), 'children' => array('count' => 2, 'only' => array('tag' => 'span'))); $this->assertTag($expected, $result_html); $expected = array('tag' => 'span', 'content' => '42', 'attributes' => array('class' => 'votes')); $this->assertTag($expected, $result_html); $this->assertRegExp('/\\$\\(\'#rating-666\'\\).rateit\\({/', $result_script); $this->assertRegExp('/readonly: false/', $result_script); $this->assertRegExp('/\\$\\(\'#rating-666\'\\).rateit\\(\'value\', 3.5\\);/', $result_script); $this->assertRegExp('#url: \'/feedback/ratings/add/Content.Article/1\'#', $result_script); $this->assertRegExp('/foreign_model: \'Article\',/', $result_script); }
/** * JSの読み込みタグを出力する(インラインオフ) * * @return void */ public function testJsNonInline() { // インラインオフ(boolean) $this->BcBaser->js('admin/function', false); $expected = '<script type="text/javascript" src="/js/admin/function.js"></script>'; $result = $this->_View->fetch('script'); $this->assertEquals($expected, $result); }
protected function fetch($tpl = '', $data = []) { $tpl = $tpl ?: $this->router['tpl']; if (method_exists($this, '__DisplayPre')) { $this->__DisplayPre(); } //hook return $this->_view->fetch($tpl, $data); }
/** * Returns the HTML of a smarty template or false if was impossible to fetch. * * @param string $template * @return boolean */ public function fetch($template) { try { $template = $this->getTemplate($template); $this->assignCommonVars(); return $this->view->fetch($template); } catch (Exception_Configuration $e) { return false; } }
public function fieldsDisplay($rid = 0) { //要嵌入规则编辑页的自定义内容,这里 $rid 为对应的规则编号,新增时为 0 $contents = []; if ($rid) { //编辑时读取原数据 $contents = Db::table('reply_basic')->where('rid', $rid)->get(); } View::with('contents', json_encode($contents ?: [])); return View::fetch($this->template . '/fieldsDisplay.html'); }
public function render($template, $_vars = array(), $fetch = false) { $view = new View($template); $this->addVars($_vars); foreach ($this->vars as $key => $var) { $view->assign($key, $var); } if ($fetch === true) { return $view->fetch($view->getTemplate()); } $view->display($view->getTemplate()); return true; }
public function fieldsDisplay($rid = 0) { //要嵌入规则编辑页的自定义内容,这里 $rid 为对应的规则编号,新增时为 0 $contents = []; if ($rid) { //顶级菜单 $contents = Db::table('reply_news')->where('rid', $rid)->where('pid', 0)->orderBy('rank', 'desc')->orderBy('id', 'ASC')->get(); //子级菜单 foreach ($contents as $k => $t) { $news = Db::table('reply_news')->where('rid', $rid)->where('pid', $t['id'])->orderBy('id', 'ASC')->get(); $contents[$k]['son_news'] = $news ?: []; } } View::with('contents', json_encode($contents ?: [], TRUE)); return View::fetch($this->template . '/fieldsDisplay.html'); }
/** * JSの読み込みタグを出力する */ public function testJs() { // ノーマル ob_start(); $this->BcBaser->js('admin/startup'); $result = ob_get_clean(); $expected = '<script type="text/javascript" src="/js/admin/startup.js"></script>'; $this->assertEqual($result, $expected); // 拡張子あり ob_start(); $this->BcBaser->js('admin/startup.js'); $result = ob_get_clean(); $expected = '<script type="text/javascript" src="/js/admin/startup.js"></script>'; $this->assertEqual($result, $expected); // インラインオフ(boolean) $this->BcBaser->js('admin/function', false); $expected = '<script type="text/javascript" src="/js/admin/function.js"></script>'; $result = $this->_View->fetch('script'); $this->assertEqual($result, $expected); }
public function _extend($attr, $content, &$view) { if (strchr($attr['file'], '.blade')) { $obj = new View(); return $obj->fetch($attr['file']); } }
$message = $MessageController->gameResult($cards); $sMainContentView = $CardsView->getCards($cards, $message); } elseif (isset($_POST['stand'])) { $previousRound = $_SESSION['cards']; $previousRound['user_id'] = $_POST['userId']; $cards = $CardsController->stand($previousRound); $message = $MessageController->gameResult($cards); $sMainContentView = $CardsView->getCards($cards, $message); } } break; case 'buyChips': break; case 'home': $homeView = new View(); $sMainContentView = $homeView->fetch('home.tpl'); default: break; } /* * Menu */ $MenuCtrl = new MenuController(); $active = $route[0]; $sMenuView = $MenuCtrl->getMenu($active); /* * NavMap */ $sNavMapView = $MenuCtrl->getNavMap($active); /* * Display the page
/** * set raw script or styles * @param null $content */ public static function raw($content = null) { if (!is_null($content)) { /** * get fullpath */ $fullPath = Config::basePath('http/web/tpl/raw/'); $fullPath .= str_replace('::', '/', $content); $fullPath .= '.tpl'; /** * fetch template */ self::$raw[] = \View::fetch($fullPath); } }
/** * 显示模板 * @param null $tpl * @param null $params * @param null $layout */ protected function display($tpl = null, $params = null, $layout = null) { is_array($tpl) && (list($tpl, $params, $layout) = array(null, $tpl, $params)); strpos($tpl, '/') || ($tpl = CTRL_NAME . '/' . ($tpl ?: ACTION_NAME)); $this->_theme && ($tpl = $this->_theme . '/' . $tpl); // 主题 $params = $params ? array_merge($this->_p, $params) : $this->_p; // 如果存在布局参数,则将模板数据写到content参数中,然后通过布局输出 if ($layout) { $params['content'] = View::fetch($tpl, $params, PATH_APP_VIEW); $tpl = $this->_theme ? $this->_theme . '/' . $layout : $layout; // 主题 } View::render($tpl, $params); }
/** * Test statistics chart * * @param array $statistics * @param string $result * @param array $settings * @dataProvider statisticsChartProvider */ public function testStatisticsChart(array $statistics, $result, array $settings) { $this->skipUnless(CakePlugin::loaded('GoogleChart'), 'Please install imsamurai/cakephp-google-chart for this test'); $View = new View(); $Helper = new TaskHelper($View, $settings); $this->assertStringMatchesFormat($result, $Helper->statistics($statistics) . $View->fetch('script')); }
public static function get($template, $variables = null) { $view = new View($template); if ($variables) { foreach ($variables as $key => $value) { $view->{$key} = $value; } } return $view->fetch(); }
public function showCorrectView(View $view) { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === "xmlhttprequest") { echo $view->fetch(); exit; } else { return $view->fetch(); } }
/** * 包含一个子模板 * @param $tpl * @param array $vars * @return string */ function contain($tpl, $vars = array()) { if ($tpl[0] == '/' && defined('VIEW_ROOT')) { $tpl = VIEW_ROOT . $tpl; } else { $tpl = __DIR__ . $tpl; } $view = new View(); $view->set($vars); $view->set('block', $this->blocks); return $view->fetch($tpl); }