Commit a864b32d authored by xiabin's avatar xiabin

编写假数据接口

parent 15f01a5d
...@@ -18,15 +18,13 @@ class AppAsset extends AssetBundle ...@@ -18,15 +18,13 @@ class AppAsset extends AssetBundle
]; ];
public $js = [ public $js = [
['common/common.js', 'position'=>View::POS_HEAD], ['common/common.js', 'position' => View::POS_HEAD],
]; ];
public $depends = [ public $depends = [
//'yii\web\YiiAsset',
//'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset' 'yii\bootstrap\BootstrapAsset'
]; ];
//定义按需加载JS方法,注意加载顺序在最后 //定义按需加载JS方法,注意加载顺序在最后
public static function addScript($view, $jsfile) public static function addScript($view, $jsfile)
{ {
...@@ -41,14 +39,31 @@ class AppAsset extends AssetBundle ...@@ -41,14 +39,31 @@ class AppAsset extends AssetBundle
$view->registerCssFile($cssfile, [AppAsset::className(), 'depends' => 'frontend\assets\AppAsset']); $view->registerCssFile($cssfile, [AppAsset::className(), 'depends' => 'frontend\assets\AppAsset']);
} }
/**
* $path 为相对baseUrl 的相对路径
*
* 生成带时间戳的图片地址
* @param $path
* @return string
*/
public static function createImageUrl($path)
{
$path = '@web/assets' . $path;
$path = self::appendTimestamp($path);
return Yii::getAlias($path);
}
public static function appendTimestamp($url) public static function appendTimestamp($url)
{ {
if (Yii::$app->assetManager->appendTimestamp && strncmp($url, '@web/', 5) === 0) { if (Yii::$app->assetManager->appendTimestamp && strncmp($url, '@web/', 5) === 0) {
$fileToCacheBust = Yii::getAlias(str_replace('@web', '@webroot', $url)); $fileToCacheBust = Yii::getAlias(str_replace('@web', '@webroot', $url));
if (($timestamp = @filemtime("$fileToCacheBust")) > 0) if (($timestamp = filemtime("$fileToCacheBust")) > 0)
$url .= "?v={$timestamp}"; $url .= "?v={$timestamp}";
} }
return $url; return $url;
} }
} }
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
* Date: 2016/9/27 * Date: 2016/9/27
* Time: 下午4:16 * Time: 下午4:16
*/ */
\frontend\assets\AppAsset::addScript($this,'@web/assets/user_center_info.js') \frontend\assets\AppAsset::addScript($this, '@web/assets/user_center_info.js')
?> ?>
<h1>user-center/info</h1> <h1>user-center/info</h1>
<img
src="<?php echo Yii::$app->user->identity->avatar === '' ? \frontend\assets\AppAsset::createImageUrl('/img/avatar.jpg') : Yii::$app->user->identity->avatar ?>">
<p> <p>
You may change the content of this page by modifying You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>. the file <code><?= __FILE__; ?></code>.
......
...@@ -9,7 +9,7 @@ require('../libs/videojs/lang/zh-CN.js'); ...@@ -9,7 +9,7 @@ require('../libs/videojs/lang/zh-CN.js');
videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf'; videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf';
window.VIDEOJS_NO_BASE_THEME = true; window.VIDEOJS_NO_BASE_THEME = true;
videojs("example_video_1").ready(function(){ videojs("example_video_1").ready(function () {
var myPlayer = this; var myPlayer = this;
// EXAMPLE: Start playing the video. // EXAMPLE: Start playing the video.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment