當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Blade::compileString方法代碼示例

本文整理匯總了PHP中Blade::compileString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Blade::compileString方法的具體用法?PHP Blade::compileString怎麽用?PHP Blade::compileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Blade的用法示例。


在下文中一共展示了Blade::compileString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     \Blade::directive('combine', function ($expr) {
         return \Blade::compileString("implode(' ', with{$expr})");
     });
     \Blade::directive('capitalize', function ($expr) {
         return \Blade::compileString("ucfirst(with{$expr})");
     });
 }
開發者ID:jairovsky,項目名稱:laravel-nested-directive-example,代碼行數:14,代碼來源:AppServiceProvider.php

示例2: register

 public static function register()
 {
     foreach (glob(__DIR__ . '/Helpers/*.php') as $file) {
         if (preg_match("/^\\w+/", basename($file))) {
             require $file;
         }
     }
     //使WordPress支持post thumbnail
     if (function_exists('add_theme_support')) {
         add_theme_support('post-thumbnails');
     }
     // 支持自定義菜單
     if (function_exists('register_nav_menus')) {
         register_nav_menus(array('header-menu' => __('topnav')));
     }
     $sidebars = array('sidebar-profile', 'Post Sidebar', 'Page Sidebar');
     foreach ($sidebars as $name) {
         register_sidebar(array('name' => $name, 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>'));
     }
     if (function_exists('add_image_size')) {
         add_image_size('60x60', 60, 60, true);
         // (cropped)
         add_image_size('245x163', 245, 163, true);
         // (cropped)
         add_image_size('337x225', 337, 225, true);
         // (cropped)
     }
     /*        //自動選擇模板的函數
             //通過 single_template 鉤子掛載函數
             add_filter('single_template', function ($single) {
                 //定義模板文件所在目錄為 single 文件夾
                 define('SINGLE_PATH', TEMPLATEPATH . '/single');
                 global $wp_query, $post;
                 //通過分類別名或ID選擇模板文件
                 $ext = '.blade.php';
                 foreach ((array)get_the_category() as $cat) :
                     if (file_exists(SINGLE_PATH . '/' . $cat->slug . $ext)) {
                         return SINGLE_PATH . '/' . $cat->slug . $ext;
                     } elseif (file_exists(SINGLE_PATH . '/' . $cat->term_id . $ext)) {
                         return SINGLE_PATH . '/' . $cat->term_id . $ext;
                     }
                 endforeach;
     
                 return $single;
             });
     */
     add_action('load-themes.php', function () {
         if ($GLOBALS['pagenow'] != 'themes.php' || !isset($_GET['activated'])) {
             return;
         }
         //僅主題啟用時執行
         flush_rewrite_rules();
         //更新偽靜態規則, 解決自定義文章類型頁麵 404 的問題
     });
     add_filter('excerpt_more', function ($more) {
         return ' ...';
     });
     add_filter('excerpt_length', function ($length) {
         return 200;
     });
     //apply_filters('logout_url', 'my_fixed_wp_logout_url');
     add_filter('show_admin_bar', '__return_false');
     add_filter('gettext', function ($translated, $text, $domain) {
         if ($domain != 'cutlass') {
             $t = __($text, 'cutlass');
             if ($t != $text) {
                 $translated = $t;
             }
         }
         return $translated;
     }, 10, 3);
     //讓主題支持語言包
     add_action('after_setup_theme', function () {
         load_theme_textdomain('cutlass', get_template_directory() . '/Resources/lang');
         $locale = get_locale();
         $locale_file = get_template_directory() . "/Resources/lang/{$locale}.php";
         if (is_readable($locale_file)) {
             require_once $locale_file;
         }
     });
     add_filter('the_content', function ($content) {
         if (!is_page()) {
             return $content;
         }
         $generated = \Blade::compileString($content);
         ob_start();
         extract($GLOBALS, EXTR_SKIP);
         try {
             eval("?>" . $generated);
         } catch (\Exception $e) {
             ob_get_clean();
             throw $e;
         }
         $content = ob_get_clean();
         return $content;
     });
 }
開發者ID:ycms,項目名稱:theme-cutlass,代碼行數:97,代碼來源:functions.php

示例3: register


//.........這裏部分代碼省略.........
         }
         if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) {
             $wp_query_obj->set('author', $current_user->ID);
         }
         return;
     });
     //在[媒體庫]隻顯示用戶上傳的文件
     add_filter('parse_query', function (\WP_Query $wp_query) {
         if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) {
             if (!current_user_can("edit_others_posts") && !current_user_can('manage_media_library')) {
                 global $current_user;
                 $wp_query->set('author', $current_user->id);
             }
         }
     });
     // 為頁麵添加 Blade 解析功能
     /** @todo 修複模板解析
      * 格式: <pre tpl="section_name">...</pre>
      * 或者: <pre tpl>...</pre>
      * 星期三[1537]2015-09-09/06:01:58.221+0800 @foolant
      */
     add_filter('the_content', function ($content) {
         if (!is_page()) {
             return $content;
         }
         extract($GLOBALS, EXTR_SKIP);
         extract(\View::getShared());
         if (preg_match_all("/\\s*<pre[^>]+tpl(\\=(\")?(\\w+)\\2)?[^>]*?>(.+?)<\\/pre>\\s*/s", $content, $ms, PREG_SET_ORDER)) {
             foreach ($ms as $match) {
                 list($all, $tplsign, $t, $tpl, $code) = $match;
                 if ($tpl) {
                     $code = "@section('{$tpl}')\n{$code}\n@endsection";
                 }
                 $generated = \Blade::compileString($code);
                 ob_start();
                 try {
                     eval("?>" . $generated);
                 } catch (\Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
                 $result = ob_get_clean();
                 $content = str_replace($all, $result, $content);
             }
         }
         return $content;
     });
     require __DIR__ . '/Helpers/admin/theme-options.php';
     /*        function auto_login_new_user($user_id)
               {
                   // 這裏設置的是跳轉到首頁,要換成其他頁麵
                   // 可以將home_url()改成你指定的URL
                   // 如 wp_redirect( 'http://www.baidu.com' );
                   //wp_redirect( home_url() );
                   //exit;
               }
               */
     // 用戶注冊成功後自動登錄,並跳轉到指定頁麵
     // 不能使用, 後台手工注冊用戶也會自動登錄
     add_action('user_register', function ($user_id) {
         if (!is_admin()) {
             wp_set_current_user($user_id);
             wp_set_auth_cookie($user_id);
         }
     });
     add_filter('get_user_option_admin_color', function () {
開發者ID:ycms,項目名稱:theme-evo,代碼行數:67,代碼來源:ThemeManager.php


注:本文中的Blade::compileString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。