Accessing CSS and JS for views - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9) +--- Thread: Accessing CSS and JS for views (/showthread.php?tid=71240) Pages:
1
2
|
Accessing CSS and JS for views - MightBeABitLate - 07-22-2018 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 --> to varying levels, but none of them work. How do I create the correct path to those files? Thanks, JMB RE: Accessing CSS and JS for views - John_Betong - 07-22-2018 Try: APPPATH .'Views/CSS/styleSheet.css'; RE: Accessing CSS and JS for views - zurtri - 07-22-2018 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'. RE: Accessing CSS and JS for views - John_Betong - 07-22-2018 @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. RE: Accessing CSS and JS for views - MightBeABitLate - 07-23-2018 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 RE: Accessing CSS and JS for views - John_Betong - 07-23-2018 Check to see if VIEWPATH has been defined. RE: Accessing CSS and JS for views - dave friend - 07-23-2018 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. RE: Accessing CSS and JS for views - MightBeABitLate - 07-24-2018 (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. 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 RE: Accessing CSS and JS for views - John_Betong - 07-24-2018 @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/blob/develop/index.php RE: Accessing CSS and JS for views - MightBeABitLate - 07-25-2018 Well, this is truly weird. All was working... but now I am getting undefined variable when I try to use base_url!!! |