CodeIgniter和Javascript / Jquery库 [英] CodeIgniter and Javascript/Jquery Library

查看:84
本文介绍了CodeIgniter和Javascript / Jquery库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我想弄清楚如何在CI上使用javascript和jquery库。

As title said, I'm trying to figure out how to use javascript and jquery libraries on CI.

按照文档中的说明,我加载库在我的控制器:

Following instruction in the docs, I load the library in my controller:

$this->load->library('javascript');



。 php:

Then, I define the location of the jQuery file (jquery.min.js) in the config.php:

$config['javascript_location'] = 'http://localhost/ci/assets/js/jquery/');

之后,我打开视图文件并放入这两行:

After that, I open the view file and put in these two lines:

<?php echo $library_src;?>
<?php echo $script_head;?> 

此处出现第一个错误:未定义变量$ library_src和$ script_head 不明白我在哪里设置它们)

First error comes up here: Undefined variable $library_src and $script_head (don't understand where I have to set them)

无论如何,我已经评论了这些行,并继续jquery lib,通过加载到我的控制器:

Anyway, I've commented these lines and continue with jquery lib, by loading it in my controller with:

$this->load->library('jquery');

下一个错误:无法加载请求的类:jquery 。 (看来它找不到lib,什么我弄糊涂了?)

Next error: Unable to load the requested class: jquery. (it seems that it can't find the lib, what i messed up?)

检查系统文件夹它看起来所有的文件到位:

Checking on system folder it looks all files are in place:

system/libraries/Javascript.php
system/libraries/javascript/Jquery.php

感谢您的帮助!

推荐答案

请务必注意,此 驱动程序 标记为实验,因此我不会依赖它。

It is important to note that this Driver is marked as experimental so I wouldn't rely on it.

此外,我个人认为这是要求混淆和头痛,尝试和直接混合应用程序的服务器端部分与客户端部分。

Also, personally I think it's asking for confusion and headaches to try and directly mix server-side portions of your applications with client side portions.

要在你的视图中使用javascript,我只是开始加载他们像这样...

To use javascript in your views, I would just start out by loading them like this...

<script type="text/javascript" src="<?= base_url() ?>path/to/jquery.js"></script>

这篇关于CodeIgniter和Javascript / Jquery库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆