当我包含jquery的插件时,我遇到了问题,图片不可见。该图像包含在css文件中。
div{background-image:url('famfamfam.png');background-repeat:no-
repeat;width:16px;height:16px}
我尝试的例子。代码放在
/webroot/protected/components/MyWidjet.php
在方法
中的init()
$cs = Yii::app()->clientScript;
$cs->registerCssFile(Yii::app()->assetManager->publish(dirname(__FILE__).'/css/
editor.css'));
$cs->registerPackage(Yii::app()->assetManager->publish(dirname(__DIR__).'/vendor/
minified/'));
$cs->registerCssFile(Yii::app()->assetManager->publish(dirname(__DIR__) .
'/vendor/minified/themes/default.min.css'));
$cs->registerScriptFile(Yii::app()->assetManager->publish(dirname(__DIR__) .
'/vendor/minified/jquery.sceditor.bbcode.min.js'));
echo CHtml::script("$(function() {
$('textarea').sceditor({
plugins: 'bbcode',
toolbar:
'bold,italic,horizontalrule,underline,strike,subscript,superscript|left,center,right,\
justify|size,color|bulletlist,orderedlist|table|
code,quote,image,link,unlink|maximize,source',
locale: 'ru',
charset: 'utf-8',
autofocus: true,
enablePasteFiltering: true,
spellcheck: true,
style: 'minified/jquery.sceditor.default.min.css'
});
});");
访问权限是777
答案 0 :(得分:0)
http://codingtip.blogspot.com/2013/09/yii-register-client-script-add-javascript-css-file.html
http://www.yiiframework.com/forum/index.php/topic/5309-clientscript-register/
http://code.dimilow.com/yii-adding-javascript-into-your-views/
http://www.waytoblogger.com/2012/08/13/register-js-css-files-in-yii-framework/
Best way of global registering ClientScript?
:d
更新:对于每个文档,您必须从index.php提供相对路径,因为所有请求都在那里处理
答案 1 :(得分:0)
主题范围内的一种方式:
将clientScript调用添加到head或themename / views / layouts / main.php中,或者在任何位置添加。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
<?php Yii::app()->clientScript->registerCoreScript('cookie'); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
.....
或者您可以将它们添加到控制器方法或其他各种地方。但这将确保Jquery无处不在:)