Welcome Guest, Not a member yet? Register   Sign In
Accessing CSS and JS for views
#1

Hi there,

I have created a file structure like this:

application
system
views
       welcome_message.php
       \JS
       \CSS
main_site

The main index.php file is in main_site and I've set up the paths to the application, system and views correctly

The problem I have is how do I access the JS files and CSS files from views that I create?

I have tried

Code:
   <!-- Bootstrap core CSS -->
   <link rel="stylesheet" href="../css/bootstrap.min.css">

to varying levels, but none of them work.

How do I create the correct path to those files?

Thanks,

JMB
Reply
#2

(This post was last modified: 07-22-2018, 03:06 PM by John_Betong.)

Try:

APPPATH .'Views/CSS/styleSheet.css';
Reply
#3

I don't put my JS and CSS in the Views directory.

I usually put it under Assets at the same level as the application.

That seems to be the 'standard'.
Reply
#4

@zurtri

>>> I usually put it under Assets at the same level as the application.
>>> That seems to be the 'standard'.

Modern "standard" is for the Application folder to be above the root according to the CI Manual.

Where is yours located?

I am finding it easier to save and upload files when stored in the Views directory.
Reply
#5

The APPPATH took me to a level below where the View folder is.

I have moved the view folder back to its default position in the application folder and I will give that a go.

JMB
Reply
#6

Check to see if VIEWPATH has been defined.
Reply
#7

(This post was last modified: 07-23-2018, 02:54 PM by dave friend.)

I think that the .htaccess file found in the application folder will prevent the <link> tag from working. You might want to reconsider creating an "assets" folder at the same level as "application" and put css, js, etc. in subfolders from there.

So with this file structure

public_html
--application
--assets
----css
----js
--system
--index.php

The following code

Code:
<link rel="stylesheet" href="assets/css/bootstrap.min.css">

should work just fine.
Reply
#8

(07-23-2018, 02:41 PM)dave friend Wrote: I think that the .htaccess file found in the application folder will prevent the <link> tag from working. You might want to reconsider creating an "assets" folder at the same level as "application" and put css, js, etc. in subfolders from there.

So with this file structure

public_html
--application
--assets
----css
----js
--system
--index.php

The following code

Code:
<link rel="stylesheet" href="assets/css/bootstrap.min.css">

should work just fine.

Hi there,

The normal way that CI seems to work is as you show above.

However, I was trying to follow the guidance which suggests that putting the application and the system files at the same level as the public folder is a good idea.

i.e

application
system
public_html
--index.php

I have managed to get this working, but I also wanted to follow the guidance of putting the views folder at the same level as application and system, rather than under the application folder.

I couldn't get this to work, so what I've ended up with is this:

app
sys
public_html
--assets
--index.php

And I use a construct like this:
Code:
<script type="text/javascript" src="<?php echo $base_url . "assets/js/mdb.min.js"?>"></script>

to get to the asset.

This works, although it seems a bit clumsy.

Am I missing something here?

JMB
Reply
#9

(This post was last modified: 07-24-2018, 03:58 PM by John_Betong. Edit Reason: spelling- not my forty )

@MightBeABitLate,

>>> This works, although it seems a bit clumsy.
>>> Am I missing something here?

Did you try:

echo VIEWPATH;

Edit:
CI Versions 3.? all have a default VIEWPATH beneath the APPPATH. The path can be over-ridden in index.php

https://github.com/bcit-ci/CodeIgniter/b.../index.php
Reply
#10

Well, this is truly weird. All was working... but now I am getting undefined variable when I try to use base_url!!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB