首页 > 解决方案 > 在 Codeigniter 中将 CSS 和 JS 包含到自定义库中

问题描述

我在 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。谁能帮我弄清楚我哪里出错了?

标签: phpcodeigniter

解决方案


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

 <?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");
        }
    }
    ?>

推荐阅读