开发者

CakePHP, including entire jquery plugin folder (with css, etc)?

I need to use some fairly complex Jquery plugins that aren't just a single .js file, but rather need an entire folder that contains css, images, etc.. I am not understanding how to include this using cakephp, I suppose I could do it from the layout in a traditional HTML manner, but it would be nicer to just do it the Cakephp way, the jquery plugin tells me t开发者_运维技巧o do this to include the folder:

<link id="bespin_base" href="/path/to"/>

But I don't quite get how to do this in cakephp.. would it be my server-side path, such as "/var/www/jquery/plugin.. etc"? Thanks for any info..

the way I normally include a jquery plugin is just like this, and similar for css but I don't want to have to manually include each file:

echo $html->script('plugin', false);


What I tend to do, because I prefer to maintain the Cake structure is place any .js files in app/webroot/js/ and place related assets in their corresponding Cake directory (e.g. app/webroot/css or app/webroot/img). Usually, this means modifying the plugin's CSS so that any url() declarations point to /img/... rather than the relative path that they usually have by default.

If you don't mind being "atypical" and want to keep it simply, then just drop everything into app/webroot/js/jquery/plugin-name/ (or something similar of your own creation). That will mix js, css and images in one directory, but there's nothing wrong with that, per se. Then, using your HTML helper, you'd reference:

echo $html->script( 'jquery/plugin-name/plugin-file.js', false );

(precise syntax may vary slightly)


If you want to create a folder in your webroot path, and access things out of it all you need to do is put a / in front of your path.

If you put a / in front of your path it makes it relative to the webroot folder otherwise it makes it relative to your JS folder.

Example

$this->Html->script( '/thirdparty/jquery/file' ); // Is equal to URL/webroot/thirdparty/jquery/file.js

Where

$this->Html->script( 'jquery/file' ); // Is equal to URL/webroot/js/jquery/file.js
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜