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


PHP TimberHelper::transient方法代码示例

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


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

示例1: is_home

<?php

/**
 * @package  WordPress
 * @subpackage  Timber
 * @since   Timber 0.1
 */
if (!class_exists('Timber')) {
    echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
    return;
}
$context = Timber::get_context();
$context['post'] = Timber::get_post();
$context['is_home'] = is_home() || is_front_page();
if ($context['is_home']) {
    $context['site_css_contents'] = TimberHelper::transient('site_css_contents', function () {
        return file_get_contents(get_template_directory_uri() . "/assets/dist/css/application.min.css");
    }, 14400);
}
$templates = array('home.twig');
Timber::render($templates, $context);
开发者ID:leroyg,项目名称:launchframe,代码行数:21,代码来源:front-page.php

示例2: testTransientAsString

 function testTransientAsString()
 {
     $transient = TimberHelper::transient('jn_test_string', 'my_test_callback', 200);
     $this->assertEquals($transient, 'lbj');
 }
开发者ID:pedrokoblitz,项目名称:centro-dialogo-aberto,代码行数:5,代码来源:test-timber-cache.php

示例3: testExpireTransient

 function testExpireTransient()
 {
     $transient = $this->_generate_transient_name();
     $first_value = TimberHelper::transient($transient, function () {
         return 'first_value';
     }, 2);
     sleep(3);
     $second_value = TimberHelper::transient($transient, function () {
         return 'second_value';
     }, 2);
     $this->assertEquals('second_value', $second_value);
 }
开发者ID:Butterwell,项目名称:timber,代码行数:12,代码来源:test-timber-cache.php

示例4: TimberPost

 * @since Boilerplate 1.0
 */
$data = Timber::get_context();
$pi = new TimberPost();
$data['post'] = $pi;
$data['body_class'] .= ' page-' . $pi->post_name;
$template_file = 'page.twig';
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css')) {
    $data['post']->css_file = $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css';
}
$contribs = TimberHelper::transient('timber-contribs', function () {
    require_once __DIR__ . '/vendor/tan-tan-kanarek/github-php-client/tan-tan-kanarek/github-php-client/client/GitHubClient.php';
    $client = new GitHubClient();
    $auth = file_get_contents(__DIR__ . '/auth.json');
    $auth = json_decode($auth);
    $client->setCredentials($auth->github->user, $auth->github->pass);
    $contribs = $client->repos->listContributors('jarednova', 'timber', array('per_page' => 100));
    $extra = count($contribs) % 6;
    $total = count($contribs) - $extra;
    $contribs = TimberHelper::array_truncate($contribs, $total);
    $ret = array();
    foreach ($contribs as $contrib) {
        $obj = new stdClass();
        $obj->login = $contrib->getLogin();
        $obj->avatar_url = $contrib->getAvatarUrl();
        $ret[] = $obj;
    }
    return $ret;
}, 1200);
$data['contribs'] = $contribs;
Timber::render(array('custom/page-' . $pi->post_name . '.twig', 'page-' . $pi->post_name . '.twig', 'page.twig'), $data);
开发者ID:ramsaylanier,项目名称:blades,代码行数:31,代码来源:page-timber.php


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