将 CSS 和 JS 包含在 Codeigniter 中的自定义库中



我在Codeigniter中创建了一个自定义库,并初始化并运行良好。我需要帮助来包含我的自定义库所需的 CSS 和 JS。我正在创建我的自定义库作为插件。

文件夹结构:

  1. 应用

    1.1. 库

    1.1.1 custom_library_folder

    • .CSS
    • .JS
    • Custom_Library_File.php
    • sk_form.php

Custom_Library_File.php

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Sdkat{
function __construct()
{}
public function sdkat_library()
{
include('sk_form.php');
}
}
?>

在sk_form.php中,我需要包含CSS和JS文件以实现我的设计目的。

sk_form.php

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/libraries/sdkat/css/style.css">
<form method="post">
<div class="input">
<label>Username: </label>
<input type="text" name="username" placeholder="Enter Username">
</div>
<div class="input">
<label>Password</label>
<input type="password" name="password" placeholder="Enter Password">
</div>
<div class="input">
<input type="submit" name="login" value="Login">
</div>
</form>

CSS没有调用,当我在浏览器中查看CSS时,我收到访问禁止!错误。

注意:我需要从我的自定义库中包含CSS和JS。谁能帮我找出我哪里出错了?

尝试此方法以包含应用程序路径上的文件

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Sdkat{
function __construct()
{
$this->load->helper('url');
}
public function sdkat_library()
{
require_once(APPPATH."custom_library_folder/sk_form.php");
}
}
?>

出于安全原因,CI 在文件系统的应用程序文件夹中添加了 .htaccess 文件。在里面,他们写得像..

<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

由于Require all denied其限制文件。

为了克服这个问题,请在"sdkat"文件夹中创建一个.htaccess,并添加以下行。

Require all granted
  • 如果需要,重新启动服务器
  • 添加Codeigniter的默认索引.html在"sdkat"文件夹及其所有子文件夹中,以避免目录浏览。

最新更新