I am using codeigniter 3.1.
I am trying to read base_url from config file .
However hardcode value is working fine for the same .
my code to read base_url is :
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />
My config is as follow :
$config['base_url'] = "http://localhost:63342/CI/";
In order to use base_url() you have to load url helper first.Load it in application/config/autoload.php like this..
$autoload['helper'] = array('url');
Make sure that your files must be in root under assets folder.
Try changing
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />
To
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/styles.css'); ?>' />
Make sure assets in root directory out side of application folder
As you have missed spelt it.
try this
set folder location this way under CI Folder
CI
application
system
assets
then css link will be
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/styles.css'); ?>' />
make sure to load url helper
$autoload['helper'] = array('url');
Related
In order to add Css & Js files to my website pages, I wanna add the following code to the functions.php file:
function cssjsloading(){
wp_enqueue_style('bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.css', false);
wp_enqueue_style('style', get_template_directory_uri().'/style.css', false);
wp_enqueue_style('header', get_template_directory_uri().'/css/header.css', false);
wp_enqueue_style('footer', get_template_directory_uri().'/css/footer.css', false);
}
add_action('wp_enqueue_scripts','cssjsloading');
instead of the following code in my <head></head> tag file, but it is not working!
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/bootstrap-rtl.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/header.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/header.css" />
I would be most grateful if you could help me
I think you should remove your false from wp_enqueue_style parameters if you do not need versioning.
Try simple wp_enqueue_style('style', get_template_directory_uri().'/style.css''); and check if this is working.
When I include the following code within my view file:
<link rel="stylesheet" href="<?php echo base_url();>css/libs/animate.min.css" type="text/css" media="all">
<!-- Font Awesome icon library -->
<link href="<?php echo base_url();?>css/libs/font-awesome.min.css" rel="stylesheet" type="text/css" media="all">
<!-- Load primary stylesheet -->
<link rel="<?php echo base_url();?>stylesheet" href="css/skin.css" type="text/css" media="all">
Nothing loads not even HTML content,
but when I remove these lines HTML content loads properly.
So how do I load my CSS files? They are in my assests/css
You have to load helper in config/autoload.php
$autoload['helper'] = array('url', 'file','form');
in config.php]
$autoload['helper'] = array('url');
and base_url() should
$config['base_url'] = '';
you did mistaken to close the php script in first css linking
you wrote .
<?php echo base_url();>
instead of
<?php echo base_url();?>
and also check that you have loaded url helper in your code or not ?
use this
<link rel="stylesheet" href="<?php echo base_url();?>css/libs/animate.min.css" type="text/css" media="all">//mistake in this line missing '?'
<!-- Font Awesome icon library -->
<link href="<?php echo base_url();?>css/libs/font-awesome.min.css" rel="stylesheet" type="text/css" media="all">
<!-- Load primary stylesheet -->
<link rel="<?php echo base_url();?>stylesheet" href="css/skin.css" type="text/css" media="all">
Stylesheet is loading for codeigniter adminpanel.
But my style css file is not applying for adminpanel.
I have added stylesheet as follows and the adminpanel url is http://www.xyz.com/demo/admin.
<link href='<?php echo base_url(); ?>assets/css/uploadify.css' rel='stylesheet' type="text/css">
$this->config->set_item('base_url', 'http://www.xyz.com/demo/admin');
<link href='<?php echo base_url(); ?>assets/css/uploadify.css' rel='stylesheet' type="text/css">
You need to load url helper to use url function
$this->load->helper('url');
<link href='<?php echo base_url(); ?>/assets/css/uploadify.css' rel='stylesheet' type="text/css">
I'm new to code igniter and I wonder why my css doesn't work when I add slash ( / ) at the end of the url ..
Can someone help me why it doesn't work ? And help me make it work ?
Try this add code to your html head:
<link rel="stylesheet" href="<?php echo site_url('css/style.css');?>" type="text/css"/>
or
<link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css"/>
CodeIgniter has method: site_url() - which generates your home url with '/' (slash) at the end.
To access public assets of your application
use this:
<link type="text/css" rel="stylesheet" href="<?php echo site_url(); ?>public/css/smoothness/jquery-ui-1.10.2.custom.min.css">
<script type="text/javascript" src="<?php echo site_url(); ?>public/js/custom.modernizr.js"></script>
Note: href="<?php echo site_url(); ?>public/css/smoothness/jquery-ui-1.10.2.custom.min.css"
I have script which uses absolute addressing in most areas, now I need to change them to relative addressing. But then the issue I am facing here is that, if for instance I have a website named www.example.com Now I want to change the links in php from
<link href="<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" />
<link href="<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" />
to
<link href="http://www.example.com/<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" />
<link href="http://www.example.com/<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" />
But I end up getting this result
<link href="http://www.example.com/http://www.example.com/themes/in/style.css" type="text/css" rel="stylesheet" />
<link href="http://www.example.com/http://www.example.com/themes/in/css/colorpicker.css" type="text/css" rel="stylesheet" />
I know something is wrong somewhere, but I still can't get it to work.. Any help with correct formatting will be highly appreciated. Sorry if my title for question is inappropriate.
Judging by the url setup:
<?php
$path = explode('/', $theme);
$theme = end($path);
?>
<link href="http://www.example.com/themes/<?= $theme ?>/style.css" type="text/css" rel="stylesheet" />
This will split the url in pieces and picks the last item which is I think is the theme name you want.
Your $theme contains this url 'http://www.example.com/themes/in/'. So if you just want the url to be like this
http://www.example.com/style.css instead of
http://www.example.com/http://www.example.com/themes/in/style.css
then remove the $theme from the href section.
hope this helps
Their would be two possible solutions, either you remove the
http://www.example.com/
from starting of <?php print $theme; ?> OR only include
theme name rather than with base bath.