1

I want to load css file from app/asset/css/tes.css This is my css file

This is my controller

This is my route

This is my view

I tried many ways but still couldn't. Please help me

I want to access the CSS file for the lala.php in the view folder, by saving the CSS file in the assets folder

1
  • Good question - but what is the error you're getting? Is it permissions on the css file? What is the output if you go direct to the route in the browser?
    – Antony
    Commented Jul 1 at 11:42

2 Answers 2

0

The problem is with your path in the controller. The correct path should be:

$path = FCPATH . '../app/asset/css/tes.css';

Or a cleaner way is:

$path = APPPATH . 'asset/css/tes.css';
0

Edit: I assumed file_as_string() is a core PHP function, but it actually is from my Common.php file:

file_as_string:

if (! function_exists('file_as_string')) {
    /**
     * Returns the files' content as string or empty string on failure.
     */
    function file_as_string(string $path): string
    {
        $filePath = $path;

        try {
            $fileContent = file_get_contents($filePath);
        } catch (ErrorException $e) {
            return '';
        }
        if ($fileContent) {
            return $fileContent;
        }

        return '';
    }
}

I use the following in my view file, but you could easily use it someplace else.

Example:

<style><?= file_as_string(APPPATH . 'asset/css/test.css') ?></style>
2
  • Can you please just explain how does it work? Is the file_as_string() a built in or codeigniter specific function? Commented Jul 4 at 19:51
  • I completely missed where the file_as_string comes from. Edited my answer for clarity. Commented Jul 5 at 7:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.