当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::render方法代码示例

本文整理汇总了PHP中Slim::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::render方法的具体用法?PHP Slim::render怎么用?PHP Slim::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim的用法示例。


在下文中一共展示了Slim::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $that = $this;
     $app = new \Slim(array('view' => 'rg\\broker\\web\\View', 'templates.path' => './src/rg/broker/web/templates'));
     $this->app = $app;
     $app->get('/', function () use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $mdParser = new \dflydev\markdown\MarkdownParser();
         $content = $mdParser->transformMarkdown(file_get_contents(ROOT . '/README.md'));
         $app->render('home.php', array('repositories' => $that->getRepositories(), 'content' => $content));
     });
     $app->get('/repositories/:repositoryName/', function ($repositoryName) use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $app->render('repository.php', array('repositories' => $that->getRepositories(), 'currentRepository' => $that->getRepository($repositoryName)));
     });
     $app->get('/repositories/:repositoryName/package/:packageName', function ($repositoryName, $packageName) use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $packageName = urldecode($packageName);
         $app->render('package.php', array('repositories' => $that->getRepositories(), 'currentRepository' => $that->getRepository($repositoryName), 'package' => $that->getPackage($repositoryName, $packageName)));
     });
     $app->run();
 }
开发者ID:researchgate,项目名称:broker,代码行数:25,代码来源:Application.php

示例2: render

 /**
  * Renders output with given template
  *
  * @param string $template Name of the template to be rendererd
  * @param array  $args     Args for view
  */
 protected function render($template, $args = array())
 {
     if (!is_null($this->renderTemplateSuffix) && !preg_match('/\\.' . $this->renderTemplateSuffix . '$/', $template)) {
         $template .= '.' . $this->renderTemplateSuffix;
     }
     $this->app->render($template, $args);
 }
开发者ID:andrearruda,项目名称:Farol-Sign-UOL-Feed,代码行数:13,代码来源:SlimController.php

示例3: renderView

 /**
  * Render view for specific action
  * @param  string $dir  directory name that contains the view files
  * @param  string $view view file
  * @return void
  */
 public function renderView($dir, $view)
 {
     $templatePath = $this->app->config->get('app.settings.renderer.template_path');
     $templateExt = $this->app->config->get('app.settings.renderer.template_ext');
     $file = $templatePath . DS . $dir . DS . $view . $templateExt;
     ob_start();
     if (isset($this->viewData)) {
         extract($this->viewData);
     }
     require $file;
     $content = ob_get_clean();
     // Store slim app to pass it to the view
     $app = $this->app;
     // Append data to view
     $this->app->view->appendData(compact('app', 'content'));
     $this->app->render($this->layout);
 }
开发者ID:zangue,项目名称:slimvc,代码行数:23,代码来源:View.php

示例4: define

<?php

if (isset($_GET['debug'])) {
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
    // System Start Time
    define('START_TIME', microtime(true));
    // System Start Memory
    define('START_MEMORY_USAGE', memory_get_usage());
}
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/', function () use($app) {
    $app->render('helloworld.php');
});
$app->run();
$xhprof_data = xhprof_disable();
if (!isset($_GET['debug'])) {
    die;
}
echo "Page rendered in <b>" . round(microtime(true) - START_TIME, 5) * 1000 . " ms</b>, taking <b>" . round((memory_get_usage() - START_MEMORY_USAGE) / 1024, 2) . " KB</b>";
$f = get_included_files();
echo ", include files: " . count($f);
$XHPROF_ROOT = realpath(dirname(__FILE__) . '/..');
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
echo ", xhprof <a href=\"http://xhprof.pfb.example.com/xhprof_html/index.php?run={$run_id}&source=xhprof_foo\">url</a>";
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:31,代码来源:index.php

示例5: testRenderTemplateWithDataAndStatus

 /**
  * Test render with template and data and status
  */
 public function testRenderTemplateWithDataAndStatus()
 {
     $s = new Slim(array('templates.path' => dirname(__FILE__) . '/templates'));
     $s->get('/bar', function () use($s) {
         $s->render('test.php', array('foo' => 'bar'), 500);
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(500, $status);
     $this->assertEquals('test output bar', $body);
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:14,代码来源:SlimTest.php

示例6: getenv

require 'lib/http.php';
require 'lib/site.php';
define('DATA_DIR', '../data/');
define('LOG_DIR', '../logs/');
define('CACHE_DIR', '../cache/');
define('DEBUG', getenv('APPLICATION_ENV'));
TwigView::$twigDirectory = 'vendor/Twig';
$twigview = new TwigView();
$app = new Slim(array('templates.path' => '../views', 'debug' => true, 'view' => $twigview));
// Add some functions that will be usable inside Twig
twig_add_function(array($twigview, 'is_float', 'var_dump'));
$app->get('/', function () use($app) {
    $data['url'] = 'http://' . get_random_url();
    $data['check_url'] = "http://{$_SERVER['SERVER_NAME']}/check?url=";
    $data['show_try'] = true;
    $app->render('index.twig', $data);
});
$app->get('/sms', function () use($app) {
    $data['url'] = 'http://' . get_random_url();
    $data['check_url'] = "http://{$_SERVER['SERVER_NAME']}/check?url=";
    $data['show_try'] = true;
    $app->render('sms.twig', $data);
});
$app->get('/check', function () use($app) {
    $url = trim($app->request()->params('url'));
    if ($url === 'random') {
        $url = get_random_url();
    }
    // Normalize URL to include "http://" prefix.
    $url2 = parse_url($url);
    if (!isset($url2['scheme'])) {
开发者ID:prakashnsm,项目名称:siteanalyzer,代码行数:31,代码来源:index.php

示例7: testSlimRenderSetsResponseStatusOk

 /**
  * Test Slim::render
  *
  * Pre-conditions:
  * You have initialized a Slim app and render an existing
  * template. No Exceptions or Errors are thrown.
  *
  * Post-conditions:
  * The response status is 404;
  * The View data is set correctly;
  * The response status code is set correctly
  */
 public function testSlimRenderSetsResponseStatusOk(){
     $data = array('foo' => 'bar');
     Slim::init();
     Slim::render('test.php', $data, 404);
     $this->assertEquals(Slim::response()->status(), 404);
     $this->assertEquals($data, Slim::view()->getData());
     $this->assertEquals(Slim::response()->status(), 404);
 }
开发者ID:ntdt,项目名称:Slim,代码行数:20,代码来源:SlimTest.php

示例8: render

 /**
  * Render template
  */
 function render($template)
 {
     $this->slim->render($template, $this->viewData());
 }
开发者ID:nikhilben,项目名称:TextPress,代码行数:7,代码来源:Textpress.php

示例9: Slim

<?php

require 'Slim/Slim.php';
//With custom settings
$app = new Slim();
//Mailchimp help route
$app->get('/mailchimp', function () use($app) {
    $app->render('mailchimp.php');
});
//Mailchimp webhook
$app->post('/mailchimp', function () use($app) {
    require_once 'MCAPI.class.php';
    $emailField = $app->request()->get('email');
    $listId = $app->request()->get('listid');
    $apiKey = $app->request()->get('apikey');
    //Make sure we have required data.
    if (empty($emailField) || empty($listId) || empty($apiKey)) {
        $app->halt(500, 'Your hook is missing required GET parameters.');
    }
    $email = $app->request()->post($emailField);
    $forename = $app->request()->post($app->request()->get('forename'));
    $surname = $app->request()->post($app->request()->get('surname'));
    $rid = $app->request()->post('id');
    //Make sure we have required data.
    if (empty($email)) {
        $app->halt(500, 'Your hook is missing email address.');
    }
    //If double opt in parameter is present, subscribe with double opt-in.
    $doubleOptIn = false;
    if (!is_null($app->request()->get('doubleoptin'))) {
        $doubleOptIn = true;
开发者ID:mikelovely,项目名称:webhooks,代码行数:31,代码来源:index.php

示例10: Slim

<?php

require 'Slim/Slim.php';
require 'Views/TwigView.php';
$app = new Slim(array('view' => new TwigView(), 'templates.path' => 'templates'));
$app->get('/', function () use($app) {
    $app->render('index.html');
});
$app->run();
开发者ID:nelsonr,项目名称:my-slim-boilerplate,代码行数:9,代码来源:index.php

示例11: render

 /**
  * Render template
  *
  * @param string $template template file to be rendered
  */
 public function render($template)
 {
     $this->slim->render($template, $this->getViewData());
 }
开发者ID:bra1nfuck,项目名称:blog.thyphoon.org,代码行数:9,代码来源:Textpress.php

示例12: Logger

        $app->response()->header('HTTP/1.1 401 Unauthorized', '');
        $app->response()->body('<h1>Please enter valid administration credentials</h1>');
        $app->response()->send();
        exit;
    }
};
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('log/your.log', Logger::WARNING));
// add records to the log
$log->addWarning('Foo');
$log->addError('Bar');
// Blog Home.
$app->get('/', function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    return $app->render('blog_home.html', array('articles' => $articles));
});
// Blog View.
$app->get('/view/(:id)', function ($id) use($app) {
    $article = Model::factory('Article')->find_one($id);
    if (!$article instanceof Article) {
        $app->notFound();
    }
    return $app->render('blog_detail.html', array('article' => $article));
});
// Admin Home.
$app->get('/admin', $authCheck, function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    return $app->render('admin_home.html', array('articles' => $articles));
});
// Admin Add.
开发者ID:rogeriopradoj,项目名称:tuto-micro_slim,代码行数:31,代码来源:index.php

示例13: function

    if (!App::user()) {
        $app->redirect("/connect/");
    }
}
//## ROUTES ##//
$app->get('/', function () use($app) {
    $params = App::start();
    $params['title'] = "Home";
    $params['page'] = "home";
    if (!App::user()) {
        $params['button'] = "Connect";
    } else {
        $params['button'] = "Logout";
    }
    $params['errors'] = array();
    $app->render('static.tpl', $params);
});
$app->map('/connect/', function () use($app) {
    $params = App::start();
    $params['title'] = "Connect";
    $params['page'] = "connect";
    $params['errors'] = array();
    # This user already has an active session
    if (App::user()) {
        $user = App::getUser();
        $params['user_email'] = $user->email;
        $params['user_name'] = $user->first_name . ' ' . $user->last_name;
        $params['button'] = "Logout";
    } else {
        # This user is not yet authenticated
        #  (it is their first visit, or they were redirected here after logout)
开发者ID:ryanj,项目名称:The-Event-Day,代码行数:31,代码来源:index.php

示例14: function

 * This is a Slim middleware route that prevents non logged in visitors to
 * access that route
 */
$locked = function () use($app) {
    return function () use($app) {
        if (!puny\User::is_logged_in()) {
            $app->redirect($app->urlFor('login'));
        }
    };
};
/**
 * This is the index page
 */
$app->get('/', function () use($app) {
    $posts = puny\Blog::get_posts(5);
    $app->render('home.php', array('posts' => $posts));
})->name('index');
/**
 * Show a single post
 */
$app->get('/blog/:url', function ($url) use($app) {
    $blog = new puny\Blog('posts/');
    $post = $blog->getPost($url);
    if (!$post->exists()) {
        $app->notFound();
        return;
    }
    $app->render('single_post.php', array('post' => $post, 'title' => $post->getTitle()));
})->name('single_post');
/**
 * A list of all the posts that has been made
开发者ID:stojg,项目名称:puny,代码行数:31,代码来源:index.php

示例15: Slim

<?php

require 'libs/php/Slim/Slim.php';
$app = new Slim(array('templates.path' => 'src/php/views'));
$app->get('/', function () use($app) {
    $app->render('main.php');
});
$app->get('/todos', function () use($app) {
    $data = array(array("label" => "Task 1", "order" => 1, "completed" => false), array("label" => "Task 3", "order" => 3, "completed" => true), array("label" => "Task 2", "order" => 2, "completed" => false));
    $response = $app->response();
    $response->header('Cache-Control', 'no-cache, must-revalidate');
    $response->header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
    $response->header('Content-type', 'application/json');
    echo json_encode($data);
});
$app->run();
开发者ID:heamon7,项目名称:Backbone-RequireJS-Todo-Example,代码行数:16,代码来源:index.php


注:本文中的Slim::render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。