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'; ?>"
Related
i have problem on load asset css(bootstrap and image) on pagination php
my main / default page is
and of course the image and css is loaded
http://localhost:8080/iklan/
....
but when i entered page 2 into..
http://localhost:8080/iklan/iklan/index/2
the image and the css bootstrap wont show
...
maybe it because the function index controller $config["base_url"] = base_url().'/iklan/index';
my css is on asset
C:\xampp\htdocs\iklan\aset
while my image is on
C:\xampp\htdocs\iklan\upload_iklan
and i call css on view like this
<link rel="stylesheet" href="aset/bower_components/bootstrap/dist/css/bootstrap.min.css">
anyone know how to load the css?
Change your base url from
$config["base_url"] = base_url().'/iklan/index';
to
$config['base_url'] = site_url('/iklan/index');
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>aset/bower_components/bootstrap/dist/css/bootstrap.min.css" />
Hope this will help you :
First set ur base url in config.php
$config['base_url']= 'http://localhost/iklan/';
and load css and js by using site_url();
site_url() returns your site URL, as specified in your config file. The index.php file will be added to the URL automatically
<link rel="stylesheet" href="<?=site_url('aset/bower_components/bootstrap/dist/css/bootstrap.min.css');?>" >
Note : make sure your css file path is correct
For more : https://www.codeigniter.com/user_guide/helpers/url_helper.html
This error occurs when I enter this code
<link rel="stylesheet" href="<?php echo base_url("asserts/css/bootstrap.min.css"); ?>" integrity="" crossorigin="anonymous">
Integrate Bootstrap on CodeIgniter.
These answers are not working for me
For getting correct result you should set base_url first inside application/config/config.php
like below
$config['base_url'] = 'http://localhost/codeigniter/';
//codigniter is demo project. set your own;
after that you should check weather you have loaded url helper or not.
to do that go to application/config/autoload.php and set the url like below
$autoload['helper'] = array('url');
finally check you have successfully set directory of css file inside base_url() function. hope that, it will work
Set the base_url in config.php
$config['base_url'] = 'http://localhost/FirstApp/';
Reason if you do not some assets and links will not work.
Use lower case name for your directories and your path.
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.min.css"); ?>" integrity="" crossorigin="anonymous">
some platforms are case sensitive.
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
I have tried base_url() function, But I didn't understand where am I wrong?
I have also mentioned - $this->load->helper ('URL'); in function abc() in controller.
Here is my code,
<link href="<?PHP echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/CSS"/>
Use below code to link your css :
<link href="<?php echo base_url(); ?>assets/css/style.css" rel="stylesheet" type="text/css">
make sure you have configure the CI configuration properly :
CONFIG.PHP
$config['base_url'] = 'http://localhost/your_project/';
$config['index_page'] = '';
AUTOLOAD.PHP
$autoload['helper'] = array('url');
It is because of the way you are referencing the css file. You can use this:
<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Or you can use this:
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
Notice the / at the start of the link, this means the browser will look from the base of your website url (your domain). If you miss it out it will use the relative part of the url, so if you are referencing a controller it will assume this is a sub folder for the location of the css file too.
You are better off with the base_url format given first, if you are using a local host for development then you will not have any problems with the url base. If you app is moved to a sub folder on another site or with a sub domain etc you will not have any problems either.
So base_url is the way to go here. More info in the docs.
http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
I am thinking you have not set tour base_url if your base url shows Ip address in links your css will not work
You need to set this value
$config['base_url'] = 'http://localhost/yourproject/';
Head
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Make sure your assets folder out side of application
application
assets
A good thing is to also autoload url helper lower case.
$autoload['helper'] = array('url');
I have develop a website using CodeIgniter and Bootstrap
I have home.php and search.php
In home.php, I have a form to submit the word to be found, and post it to search.php,
and Bootstrap works fine in search.php, at this way
but I also have function in search.php which can be accessed within url
e.g. mysite.com/search/with/words/
and Bootstrap didn't works at this way
So much thank you before
As i understood your question you can use
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/js/bootstrap.js">
So file structer would be
1. application
2. system
3. assets
- css
1. bootstrap.css
- js
1. bootstrap.js
4. index.php
5. .htaccess