Twitter Bootstrap Path Breaks When Not on Homepage - php

I am currently testing my website on the local server. I have issues with twitter bootstrap's path in my header view.
On my homepage this path works fine:
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
When I move to sub-page via link:
<a href="index.php/home_controller/getFilmDetails?id...
Which translates to:
http://localhost/www.mywebsite.co.uk/index.php/home_controller/getFilmDetails?id=114
Controller code:
$this->load->view('/header/header_home');
$this->load->view('movies_details_view',$data);
$this->load->view('footer_home');
Path to twitter bootstrap does not work, and I need to change the path to:
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
How do I make the path work on all pages?

In your Controller do this:
$this->load->helper('url');
$this->load->view('/header/header_home');
$this->load->view('movies_details_view',$data);
$this->load->view('footer_home');
Inside you header view do this:
<link href="<?php echo base_url('/bootstrap/css/bootstrap.css') ?>" rel="stylesheet">

Related

Synfony3: How to work with assets and path

Hello everyone: i'm deploying my project. Pointed the URL to the web folder when I call the url the login page shows but with non css or js, and the buttons calls doesn't work.
This is how I call the css/js or links to some path
<link href="{{ asset('css/main.css') }}" rel="stylesheet" />
add
and this is what it translate
<link href="/project/web/css/main.css" rel="stylesheet">
and that should translate it as
<link href="/css/main.css" rel="stylesheet">
Any help?
thanks

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

External CSS link is not working in codeIgniter

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');

Linking CSS in Wordpress with PHP and bloginfo()

I'm attempting to link my CSS file with my header.php file for a Wordpress site I'm working on, but I'm having a little trouble following along.
I was told to set it up like so:
<link href="<?php bloginfo('stylesheet_url');?>" rel="stylesheet">
Below is my current code:
<link href="<?php bloginfo('/style.css');?>" rel="stylesheet">
However if you look at the current state of the site, http://thenerdup.com, it's obvious that the CSS file is not linked properly.
For what it's worth, this is the tutorial I'm following along with: http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial
I'm currently on the part about editing the header.
Thanks for any help.
Actually it should be
<link href="<?php bloginfo('stylesheet_url');?>" rel="stylesheet">
So it'll echo/print the url of your stylesheet.
Here bloginfo() is a function and stylesheet_url is a parameter of this function. There are other parameters too, for example if you write bloginfo('name') then it'll print the name of your blog.
Also you can use
<link href="<?php echo get_stylesheet_uri();?>" rel="stylesheet">
Read more at Codex.

Loading CSS, JS in CodeIgniter

I am kinda newbie to CodeIgniter. Somehow I set up the development environment and ready to go. But loading the CSS, JS into page seems a lot more confusing. Before moving, I googled a lot but the base_url solution is not helping.
Part of View :
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
<link href='css/fullcalendar.css' rel='stylesheet'>
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
<link href='css/opa-icons.css' rel='stylesheet'>
<link href='css/uploadify.css' rel='stylesheet'>
Controller :
public function dashboard()
{
$this->load->helper('url');
$this->load->view('templates/css_styles');
$this->load->view('templates/top_bar');
$this->load->view('templates/left_menu');
$this->load->view('pages/dashboard');
$this->load->view('templates/footer');
$this->load->view('templates/js_end');
}
public function index()
{
$this->load->helper(array('form'));
$this->load->view('login');
}
route.php :
$route['default_controller'] = "welcome/dashboard";
$route['404_override'] = '';
$route['dashboard'] = 'welcome/dashboard';
If I put the dashboard method as default controller, the page is loading fine. But when I change it to just welcome, which is a login form and redirect to welcome/dashboard, the page doesn't load any CSS. Just all HTML texts. The dashboard page is just pure HTML, no PHP code written yet.
Please help me what might causing this.
What's wrong with base_url()?
<link href="<?php echo base_url('css/bootstrap-responsive.css')?>" rel="stylesheet">
make sure you load URL helper, I recommend autoloading it: go to application/config/autoload.php and add it to the helper array:
$autoload['helper'] = array('url');
You can use the link_tag() in html_helper.php to help get the paths correct.
First load the helper (I usually have it autoloaded)
$this->load->helper('html');
Then you can reference css like this:
echo link_tag('css/bootstrap-responsive.css');
The advantages are the function tries to build the correct absolute URL to the css file and it automatically sets the rel attribute to stylesheet and the type attribute to text/css.
Also you should have Chrome, Safari, or Firebug for Firefox so that you can inspect the code and see if the CSS files are being loaded or if they are not found. This will help with debugging.
Make sure you have a leading slash before your css folders:
<link href="/css/bootstrap-responsive.css" rel="stylesheet">
And make sure that the files are indeed located in /css off your web root, not inside the application folder.
first you need load helper url
$this->load->helper('url');
and then on controller
$this->data =site_url()."your css file";
then on your view
<link rel="stylesheet" type="text/css" href="<?php echo $css; ?>">
its simple.you can view full article load css/js

Categories