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
Related
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"/>
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"/>
In the beginning of the PHP file, I am defining the ROOT as
define('ROOT', dirname(__FILE__));
It works when i use something like
require_once(ROOT . DIRECTORY_SEPARATOR . 'config/bootstrap.php');
However, when using the same ROOT while including the css within the HTML seems to create a problem.
<html>
<head>
<title>PrePress ยท Login</title>
<link type="text/css" href=<?php echo ROOT . DS . 'views/type.css ?> rel="stylesheet">
</head>
<body>
Test
</body>
</html>
On tracing the path of the CSS file, the full path starts with http://localhost:8888/Users/.... Here I simply want my path to start from /Users/ which will be able to find my css file, whereas having the localhost changes the path and the file can no longer be found.
<link type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"]."/views/type.css"; ?>" rel="stylesheet" />
You do not need to use that format in an href. Just use
<link type="text/css" href="views/type.css" rel="stylesheet">
To give a relative address, which makes the code much more transportable
use
<?php $path = glob($_SERVER["DOCUMENT_ROOT"]."/views/type.css"); ?>
<link type="text/css" href="<?php $path; ?>" rel="stylesheet" />
You have to set the base url and that should link to your project folder. If you are not using a framework then I suggest you do.
Once you have set your base url you can call css and javascript from your header and footer respectively, and include the header and footer on your pages i.e $this->load->view('includes/header); and $this->load->view('includes/footer);
This is how you would typically call your scripts, I have only mentioned the href property within the tags as you should know the rest.
<script href="<?php echo base_url('link to your script goes here');?>" />
<link href="<?php echo base_url('link to your sheet goes here);?> />
I use XAMPP and CI 2.14
(I know it's sounds ridiculous, but...) I don't know how to refer to a css file from a view. I've read and tried a lot of examples but, obviously I do something wrong...
<link rel="stylesheet" href="<?php echo base_url();?>css/main.css" type="text/css" />
The base url is: http://localhost/myapp/
Where should I put then main.css file (now is in the webroot/myapp/css folder), and how to reference it from a codeigniter view?
create folder assets:
path is: /assets/css/your_file.css
<link rel="stylesheet" href="/assets/css/your_file.css" type="text/css" />
Try to put the css folder inside the application folder, like this:
/yourapp/application/css/
And then
<link rel="stylesheet" href="<?php echo base_url();?>application/css/main.css" type="text/css" />
My header.php doesn't link to default.css properly. Page loads without CSS applied.
If I view the source of the page and click on the link to .css file - 403 Forbidden shows up in Source View.
config.php
$config['base_url'] = 'http://localhost/dev/';
routes.php
$route['default_controller'] = "page/view";
$route['404_override'] = '';
pages is the controller
view is the method
application/view/templates/header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="<?php echo base_url(); ?>application/css/default.css" rel="stylesheet" type="text/css" />
<title><?php echo $title; ?></title>
</head>
<body>
application/css/default.css
* {margin:0;padding:0;}
body {
background-image: url(../images/bg.gif);
background-repeat: repeat-x;
...
}
application/images/
-- bg.gif GIF Image 1KB
Is a good practice to put css files in "assets" directory instead of "application". Move the file to a directory called assets/css in your DOCUMENT_ROOT and change this line:
<link href="<?php echo base_url(); ?>application/css/default.css" rel="stylesheet" type="text/css" />
to:
<link href="<?php echo base_url(); ?>assets/css/default.css" rel="stylesheet" type="text/css" />
This is the default state of Codeigniter. You need to create a .htaccess file in your css and image directory and put this code (it should work, I am using it):
allow from All
Or you can create a public folder in the root folder and not have this problems.
Leave base_url in config blank.Like this:
$config['base_url'] = '';