CodeIgniter: Add css link - php

I am trying to use the PHP Framework CodeIgniter for a PHP project. I never used it before. According to its documentation I activated the helper URL and included the css link as shown below:
$autoload['helper'] = array('url');
<link rel="stylesheet" type="text/css"
href="<?php echo base_url();?>public/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css"
href="<?php echo base_url();?>public/css/style.css"/>
Unfortunately the page is not able to load the css. Obviously if I put the compiled CSS link the page is able to load it.
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

Base_url() does not add a trailing slash. You need a forward slash in between the PHP code and public in the link href.
Say your base url is /htdocs/website/, the way you currently have it set up would print out /htdocs/websitepublic/css/style.css.
Here is the fixed code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url();>/public/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();>/public/css/style.css"/>

Related

Dynamic link in css stylesheet with PHP variable

I'm building a dynamic page template for wordpress (which means it has to work at least 4 different domain without changing anything like links etc.) and I added a custom css link like this:
<link type="text/css" rel="stylesheet" href="https://mywebsite.com/wp-content/themes/mytheme/css/page-food.css">
I can reach the server home in a variable like $home_path. Or the theme main folder like $theme_path. So is there any possible way to add the href a PHP variable?
I mean
<link type="text/css" rel="stylesheet" href="$theme_path/css/page-food.css">
just add php start and end tags there
<link type="text/css" rel="stylesheet" href="<?=$theme_path?>/css/page-food.css">
wordpress css call in daynamic path
<link href="<?php echo get_template_directory_uri(); ?>/css/fonts.css" type="text/css" rel="stylesheet">

bootstrap styles not work with code igniter

bootstrap folder was placed in root folder. styles were loaded in header sections of view files like this. but it's not worked. please help to solve this.
<link href="<?php echo base_url('bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
<link href="<?php echo base_url('bootstrap/css/mystylesheet.css'); ?>" rel="stylesheet">
<script src="<?php echo base_url('bootstrap/js/jquery.min.js'); ?>"></script>
<script src="<?php echo base_url('bootstrap/js/bootstrap.min.js'); ?>"></script>
<title>::CMSys || Add Division::</title>
</head>
You have forgot type="text/css"
<link type="text/css" href="<?php echo base_url('bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
<link type="text/css" href="<?php echo base_url('bootstrap/css/mystylesheet.css'); ?>" rel="stylesheet">
Make sure you have set your base url in the application config.php
Make sure you have the bootstrap folder out side of the application
folder.
$config['base_url'] = 'http://localhost/yourproject/';
Or something like
$config['base_url'] = 'http://www.yourdomain.com/';
And autoload the url helper
$autoload['helper'] = array('url');
If not place it in the construct area of controller. http://www.codeigniter.com/user_guide/general/controllers.html#class-constructors
And make sure you have named your classes and filenames correct as explained here
http://www.codeigniter.com/user_guide/general/styleguide.html#file-naming
http://www.codeigniter.com/user_guide/general/styleguide.html#class-and-method-naming
You may need a htaccess file in the main directory try some of these https://github.com/wolfgang1983/htaccess_for_codeigniter

Unable to access stylesheets in codeigniter

I am new to the CodeIgniter, however when i try to link bootstrap files to my project blank(white) screen appears.
<link rel="stylesheet" type="text/css" href="<?php echo base_url("assets/css/bootstrap.min.css");?>" >
I put all bootstrap files inside assets folder which is in the same level as root directories as follows
application
assets
css
bootstrap.min.css
system
I tried alternative such as
<link rel="stylesheet" type="text/css" href="<?=base_url();?>assets/css/bootstrap.min.css" >
And
<link rel="stylesheet" type="text/css" href="<?php echo link_tag("assets/css/bootstrap.min.css")?>" >
none of these seems to work, what should i do? someone help me please!
Let's suppose you have a file in the view folder (application/views) called home_view.php and another file in css folder(application/assets/css/bootstrap.min.css).
In order to link your css file into the view you need to add this line in your home_view.php:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/assets/css/bootstrap.min.css"/>
If your assets folder is in the same level directory as application folder you can make a constant in constants.php(application/config/constants.php) file:
define('MY_ASSETS', 'assets/');
and your link will be:
<link rel="stylesheet" type="text/css" href="<?php echo MY_ASSETS; ?>css/bootstrap.min.css"/>

how to add site path in xammp localhost

i have a source code of a CMS the cms back-end working perfectly but in front-end shows errors the css not working properly i was searching for the solution then find
<!-- language: lang-html -->
<link href="<?php echo $sitepath; ?>/Assets/css/bootstrap.css" rel="stylesheet" media="screen"/>
<link href="<?php echo $sitepath; ?>/Assets/css/font-awesome.min.css" rel="stylesheet"/>
<link href="<?php echo $sitepath; ?>/Assets/css/bootstrap-responsive.css" rel="stylesheet" media="screen"/>
<link href="<?php echo $sitepath; ?>/Assets/css/sitestyles.css" rel="stylesheet" media="screen"/>
has not fixed
and am try to fix in include.php file here is the include file
$sitepath="http://".$_SERVER['HTTP_HOST'];
//Replace with your domain name if you wish
//$sitepath="http://www.example.com";
this code working on my server but while use this code on my localhost xampp to change
$sitepath="http://localhost/cms".$_SERVER['HTTP_HOST'];
//Replace with your domain name if you wish
//$sitepath="http://www.example.com";
still shows the top code css not working the url shows
localhost/cms/localhost/index.php
like this what i do help please

Header template wont alway pull up css

I am new to php, but suspect there is a simple solution that I am not aware of.
I have made a template for the header on every page, but when the user loads pages the css page changes in relation to their current page.
How do I have php track how many levels up in a folder the user is so I can pull the css from anywhere in the website?
<link rel="stylesheet" href="../templates/css/css.css" type="text/css" />
That is my current link to css, but for a page further down in folders I need it to add additional ../
You should use an absolute path from the root of the website (note, no ".." just a "/"):
<link rel='stylesheet' href='/templates/css/css.css' type='text/css' />
Will always work, as long as your css is at:
http://yourwebsite.com/templates/css/css.css
you shouldn't be using a relative path then. Why not just do something like:
<link rel="stylesheet" href="http://www.mysite.com/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />
whichever suits your needs - since you may be working locally and have a strange file structure, or a shared style directory for example
The best method is to use:
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />

Categories