Loading css and javascript in codeigniter - php

I am creating Web app in codeigniter.
When I link css and javascript file in my VIEW and runs on server it gives plain text.
My css style can't apply on the page. Even with the javascript file also.
Is there any configuration required !!!

you mentioned in your comment that you are calling css like but codeigniter doesn't take full path like that. you need to use base_url() for getting external css and JavaScript files.use below example for call css and js files
<link href="<?php echo base_url(); ?>folder/style.css">
<script type="text/javascript" src="<?php echo base_url(); ?>folder/abc.js"></script>

Related

How to Properly set base_url() in codeigniter?

I am working on an application based on codeigniter, i have created a global layout page on that i page i have included all the css, js and other images that is in assets folder in codeigniter root.
i have included those files like below code
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/front/website/static/fonts/icomoon-greycom/css/style.css">
when i visit homepage https://mypage.com, it works fine
it loads those files as
https://mypage.com/assets/front/website/static/font/icomoon-greycom/css/style.css
but when i visit other links like.
https://mypage.com/region/india
den it load
https://mypage.com/region/india/assets/front/wesbite/static/font/icon-greycom/css/style.css
but i want it should load only https://mypage.com/assets/assets/front/wesbite/static/font/icon-greycom/css/style.css
in my config.php page
$config['base_url'] = "https://www.mypage.com/";
how to solve this issue.
Put the asset path inside the base_url function (as per the docs).
e.g.
<?php echo base_url('assets/front/website/static/fonts/icomoon-greycom/css/style.css'); ?>
Use this:
<link rel="stylesheet" href="<?php echo site_url(); ?>assets/front/website/static/fonts/icomoon-greycom/css/style.css">
Can Use
href="<?php echo base_url().'assets/front/website/static/fonts/icomoon-greycom/css/style.css'; ?>"

CSS not loading with codeigniter

IM trying to load some css directly within my view file, but its not working.
in my view file I have this.
<link href="<?php echo base_url(); ?>assets/css/core.css" rel="stylesheet" type="text/css" />
The assets folder is at the same level as Application
when I view source on the webpage it shows me this
demo.example.com/assets/css/core.css
but when i click the link to see if it's working the url becomes this...
http://demo.example.com/admin/demo.example.com/assets/css/core.css
not sure what I am doing wrong? Should I be adding something to my htaccess file?
Thanks in advance.
You don't need to include the base_url() in your path because the webserver already knows your at www.example.com/admin and auto includes that.
Just use
<link href="/assets/css/core.css" rel="stylesheet" type="text/css" />
Edit: Or actually you need to include the http: prefix on your base_url like wolfgang1983 said.
See this answer on CSS absolute and relative link paths. https://stackoverflow.com/a/17621358/3585500

Add domain URL to href and src relative paths

I'm using a MVC model and I can invoke webpages with URLs like http://mywebsite.com/product/productid.html. My folder structure is the following:
views - the views folder
js - the javascript and jquery folder
css - the stylesheets folder
images - the images folder
In views folder are contained web pages used to show data to the users. They can include scripts, images and stylesheets. The following snippet is incorrect
<link rel="stylesheet" href="css/style.css" media="all" type='text/css' />
since the webpage is called with the URL above, and css can't be found with a relative path. To solve the problem, I have defined a DOMAIN variable in PHP and changed the code into
<link rel="stylesheet" href="<?php echo DOMAIN;?>css/style.css" media="all" type='text/css' />
This works, but forces me to add the <?php echo DOMAIN;?> snippet to each href and src attribute on each page. Is it possible to automate it? I've tought to use the :before selector but I don't have idea how to use it in this case.
Any ideas? Thanks in advance.
:before only applies to CSS, so that's not of use here.
There's really no way to do automatically add it in PHP that wouldn't be cpu-intensive, and/or require a significantly more complex setup than it sounds like you have right now. Using find-and-replace in your code editor is the best option.
Using <?= DOMAIN; ?> instead would be shorter, BTW. (See this question for more info)

How do I load css files with a view in CodeIgniter?

I am currently trying to load a css file into a CodeIgniter view in the follow manner:
<link rel="stylesheet" href="<?php echo base_url(); ?>css/style.css">
A blank page is loaded. It seems that when I call the base_url function in the view the page doesn't load because the same thing happens when I call base_url() else where in the view but the page actually loads without css when I remove the calls to that function. Is there something that I need to require in order for the page to load?
From: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
This helper is loaded using the following code:
$this->load->helper('url');
The following functions are available:
...
You need to first load the helper either in the method called, or in the class constructor.
Try import annotation.
<style> #import url('<echo base_url()?>/css/styles.css'); </style>
You could do like this:
<link href="<?php echo base_url('assets/css/bootstrap.min.css') ?>" rel="stylesheet">

using lightbox with code igniter

I'm trying to use Lightbox with my CodeIgniter application. Lightbox says to put the following in the head tag:
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
I already had a js folder and a css folder, so I put the js and css folders that came with lightbox within my js and css folder. I changed the 3 script tags and link tags to:
<script type="text/javascript" src="js/js/prototype.js"></script>
<script type="text/javascript" src="js/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/js/lightbox.js"></script>
<link rel="stylesheet" href="css/css/lightbox.css" type="text/css" media="screen" />
(added the /js and /css)
in the view file I have
<img name="<?php echo $row->Thumb;?>" src="http://www.doublediamondllc.com/uploaded/portfolio/thumbs/<?php echo $row->Thumb;?>" alt="">
This displays the thumbnail version, and then when clicked I want it to go to the lightbox, but now it goes to a new tab with the large image.
I've used lightbox before and have always gotten it to work, I'm not really sure what the problem is now, and I tried moving the files all around to different spots but nothing worked.
Thanks in advance!
It seems like the .js isn't getting loaded properly. Try using Firebug, and see if any errors pop up. Alternatively, check the links in the source for the page, and make sure they are pointing to the lightbox js files correctly. If you are using Firefox, view source; the links to the js files should appear as clickable links; click on them and make sure the js file appears, and not a 404 or some other error. Otherwise copy and paste the link attributes to your browser and check the .js paths are correct.

Categories