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


PHP FileHelper::localize方法代码示例

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


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

示例1: getText

 public function getText()
 {
     $file = FileHelper::localize($this->textFile);
     //        FileHelper::getMimeType()
     $f = file('uploads/' . $file->name);
     return $f;
 }
开发者ID:kd-brinex,项目名称:kd,代码行数:7,代码来源:UploadForm.php

示例2: renderFile

 public function renderFile($viewFile, $params = array(), $context = null)
 {
     $viewFile = \Yii::getAlias($viewFile);
     if ($this->theme !== null) {
         $viewFile = $this->theme->applyTo($viewFile);
     }
     if (is_file($viewFile)) {
         $viewFile = \yii\helpers\FileHelper::localize($viewFile);
     } else {
         throw new \yii\base\InvalidParamException("The view file does not exist: {$viewFile}");
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     if ($this->beforeRender($viewFile)) {
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /** @var ViewRenderer $renderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $output);
     }
     $this->context = $oldContext;
     return $output;
 }
开发者ID:rocketyang,项目名称:mincms,代码行数:33,代码来源:View.php

示例3: renderFile

 /**
  * Renders a view file.
  *
  * If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
  * as it is available.
  *
  * The method will call [[FileHelper::localize()]] to localize the view file.
  *
  * If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
  * Otherwise, it will simply include the view file as a normal PHP file, capture its output and
  * return it as a string.
  *
  * @param string $viewFile
  *            the view file. This can be either an absolute file path or an alias of it.
  * @param array $params
  *            the parameters (name-value pairs) that will be extracted and made available in the view file.
  * @param object $context
  *            the context that the view should use for rendering the view. If null,
  *            existing [[context]] will be used.
  * @return string the rendering result
  * @throws InvalidParamException if the view file does not exist
  */
 public function renderFile($viewFile, $params = [], $context = null)
 {
     $viewFile = $this->findViewFileByDefault($viewFile);
     if (is_file($viewFile)) {
         $viewFile = FileHelper::localize($viewFile);
     } else {
         throw new InvalidParamException("The view file does not exist: {$viewFile}");
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     $this->_viewFiles[] = $viewFile;
     if ($this->beforeRender($viewFile, $params)) {
         Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /* @var $renderer ViewRenderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $params, $output);
     }
     array_pop($this->_viewFiles);
     $this->context = $oldContext;
     return $output;
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:55,代码来源:View.php

示例4: findViewFile

 /**
  * Changes:
  *
  * * if view file does not exist, find view file using $this as context.
  *
  * @inheritdoc
  */
 protected function findViewFile($view, $context = null)
 {
     $path = parent::findViewFile($view, $context);
     if ($this->theme !== null) {
         $path = $this->theme->applyTo($path);
     }
     if (!is_file($path)) {
         //find default view file
         return $this->findDefaultViewFile($view, $context);
     }
     return FileHelper::localize($path);
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:19,代码来源:View.php

示例5: renderFile

 /**
  * Renders a view file.
  *
  * If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
  * as it is available.
  *
  * The method will call [[FileHelper::localize()]] to localize the view file.
  *
  * If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
  * Otherwise, it will simply include the view file as a normal PHP file, capture its output and
  * return it as a string.
  *
  * @param string $viewFile the view file. This can be either an absolute file path or an alias of it.
  * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
  * @param object $context the context that the view should use for rendering the view. If null,
  * existing [[context]] will be used.
  * @return string the rendering result
  * @throws InvalidParamException if the view file does not exist
  */
 public function renderFile($viewFile, $params = [], $context = null)
 {
     $viewFile = Yii::getAlias($viewFile);
     if ($this->theme !== null) {
         $viewFile = $this->theme->applyTo($viewFile);
     }
     if (is_file($viewFile)) {
         $viewFile = FileHelper::localize($viewFile);
     } else {
         if (strpos($viewFile, $context->getViewPath()) === 0) {
             $viewFile = Yii::getAlias('@kalibao/views') . substr($viewFile, strlen($context->getViewPath()), strlen($viewFile));
         }
         if (!is_file($viewFile)) {
             throw new InvalidParamException("The view file does not exist: {$viewFile}");
         }
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     $this->viewFiles[] = $viewFile;
     if ($this->beforeRender($viewFile, $params)) {
         Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /* @var $renderer ViewRenderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $params, $output);
     }
     array_pop($this->viewFiles);
     $this->context = $oldContext;
     return $output;
 }
开发者ID:kalibao,项目名称:magesko,代码行数:60,代码来源:View.php

示例6: generateIndexYii1

 protected function generateIndexYii1($source, $target, $version, $language, $type = 'guide')
 {
     $this->stdout('populating elasticsearch index...');
     try {
         // first delete all records for this version
         $version = $this->version;
         $chapters = [];
         $sections = [];
         $file = "{$source}/toc.txt";
         $file = FileHelper::localize($file, $language, 'en');
         $lines = file($file);
         $chapter = '';
         foreach ($lines as $line) {
             // trim unicode BOM from line
             $line = trim(ltrim($line, ""));
             if ($line === '') {
                 continue;
             }
             if ($line[0] === '*') {
                 $chapter = trim($line, '* ');
             } else {
                 if ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
                     $chapters[$chapter][$matches[1]] = $matches[2];
                     $sections[$matches[2]] = [$chapter, $matches[1]];
                     // elasticsearch
                     $file = $target . '/' . $matches[2] . '.html';
                     if (!file_exists($file)) {
                         echo "file not found: {$file}\n";
                         continue;
                     }
                     $html = file_get_contents($file);
                     SearchGuideSection::createRecord(basename($file, '.html'), $matches[1], $html, $this->version, $this->language, $type);
                 }
             }
         }
         $file = $type == 'blog' ? "{$source}/start.overview.txt" : "{$source}/index.txt";
         $file = FileHelper::localize($file, $language, 'en');
         $lines = file($file);
         if (($title = trim($lines[0])) === '') {
             $title = $type == 'blog' ? 'Building a Blog System Using Yii' : 'The Definitive Guide for Yii';
         }
         $title = str_replace('Yii', "Yii {$version}", $title);
         FileHelper::createDirectory($target);
         file_put_contents("{$target}/index.data", serialize([$title, $chapters, $sections]));
         $this->stdout("done.\n", Console::FG_GREEN);
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             $this->stdout("!!! FAILED !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
             $this->stdout((string) $e . "\n\n");
         } else {
             throw $e;
         }
     }
 }
开发者ID:philippfrenzel,项目名称:yiiframework.com,代码行数:54,代码来源:GuideController.php

示例7: testLocalizedDirectory

 public function testLocalizedDirectory()
 {
     $this->createFileStructure(['views' => ['faq.php' => 'English FAQ', 'de-DE' => ['faq.php' => 'German FAQ']]]);
     $viewFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'faq.php';
     $sourceLanguage = 'en-US';
     // Source language and target language are same. The view path should be unchanged.
     $currentLanguage = $sourceLanguage;
     $this->assertSame($viewFile, FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
     // Source language and target language are different. The view path should be changed.
     $currentLanguage = 'de-DE';
     $this->assertSame($this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $currentLanguage . DIRECTORY_SEPARATOR . 'faq.php', FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
 }
开发者ID:howq,项目名称:yii2,代码行数:12,代码来源:FileHelperTest.php

示例8: getToc

 public function getToc()
 {
     if ($this->_toc === null) {
         $file = $this->basePath . DIRECTORY_SEPARATOR . $this->tocFile . '.txt';
         $file = FileHelper::localize($file, $this->language, 'en');
         $lines = file($file);
         $chapter = '';
         foreach ($lines as $line) {
             // trim unicode BOM from line
             $line = trim(ltrim($line, ""));
             if ($line === '') {
                 continue;
             }
             if ($line[0] === '*') {
                 $chapter = trim($line, '* ');
             } elseif ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
                 $this->_toc[$chapter][$matches[1]] = $matches[2];
                 $this->_sections[$matches[2]] = array($chapter, $matches[1]);
             }
         }
     }
     return $this->_toc;
 }
开发者ID:netyum,项目名称:yiiframework.com,代码行数:23,代码来源:Yii1GuideRenderer.php


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