I am using CodeIgniter bootstrap stylesheet link URL can't work properly.
Controller code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->helper('url');
$data['title'] = "Login Home";
$this->load->view('home',$data);
}
}
HTML Code
<div class="container">
<div class="row">
<div class="col-lg-offset-4 col-lg-4">
<div class="well">
<h3>welcome</h3>
</div>
</div>
</div>
</div>
CSS link code
<link href="<?php echo base_url("register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
Place assets out side of application. Reason the .htaccess in application folder blocks it.
application
assets
assets > bootstrap > css > bootstrap.css
assets > bootstrap > js > bootstrap.js
system
index.php
First I would suggest
config/autoload.php
$autoload['helper'] = array('url');
then
config/config.php Set your base url
$config['base_url'] = 'http://localhost/projectnmame/';
in config.php set this line
$config['base_url'] = 'http://localhost/register/';
root directory set this way
application
system
bootstrap-3.3.6
ensure that you are using .htaccess file in your codeigniter application.create one folder assets.place your css file in assets folder.after that link that file like this,
in application folder config file paste this,
$root = 'http://' . $_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);;
$config['base_url'] = $root;
<link href="<?php echo base_url("assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
if you are not using htaccess file,
<link href="<?php echo base_url("index.php/assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
try this....
Related
I am trying to create a PDF with my company logo using the dompdf library but I have a PDF without my logo. I can try the following code.
Welcome Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('pdf');
}
public function index()
{
$html = $this->load->view('welcome_message', [], true);
$this->pdf->createPDF($html, 'mypdf', false);
}
}
Welcome_view:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<body>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<img src="<?php echo base_url() ?>/img/un6.png'">
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>
</body>
</html>
and also included dompdf files application/libraries folder:
PDF.php file for dompdf file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(dirname(__FILE__) . '/dompdf/autoload.inc.php');
class Pdf
{
function createPDF($html, $filename='', $download=TRUE, $paper='A4', $orientation='portrait'){
$dompdf = new Dompdf\DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper($paper, $orientation);
$dompdf->render();
if($download)
$dompdf->stream($filename.'.pdf', array('Attachment' => 1));
else
$dompdf->stream($filename.'.pdf', array('Attachment' => 0));
}
}
?>
How can I do this
The problem is here:
<img src="<?php echo base_url() ?>/img/un6.png'">
DomPDF needs all external resources to be referenced as file paths, not URLs.
You could, for instance try this:
<img src="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/img/un6.png'">
or also something like:
<img src="<?php echo FCPATH; ?>/img/un6.png'">
(FCPATH is Codeigniter's front controller path... the server path to the main index.php file that orchestrates everything in CI)
DomPDF requires base64 encoded images in order to display it properly in PDF format.
Convert the image to base64 using this tool https://www.base64-image.de/
It will give a html tag, just use it in your HTML PDF code
I'm totally new to Codeigniter and Grocery CRUD, but I very like the concept, so I'm trying to make my little app with these frameworks.
So, right now the login system is working and after login on the "home" page, I see my Grocery CRUD table, it's filled, so far it's okay...
My problem is, that I can't use any function: add, edit, view, search is not working, it gives me 404 error for example this is one edit link:
http://subdomain.mysite.com/index.php/home/edit/1
The site is on a subdomain, I don't know if could be relevant or not.
This is my base_url:
$config['base_url'] = '/';
If I change this to '', the base_url(); method doesn't gives me the right value, I assume it's because the subdomain.
This is my complete "Home" view:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My system</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 class="page-header text-center">My system</h1>
<div class="row">
<div class="container text-right">
<?php
$user = $this->session->userdata('user');
extract($user);
?>
<p class="d-inline"><b>Logged in as:</b> <i><?php echo $fname; ?></i></p>
</div>
<div class="container">
<?php
$crud = new grocery_CRUD();
$this->grocery_crud->set_table('mobil_table');
$this->grocery_crud->columns('mobile_number', 'package_name', 'package_date');
$output = $this->grocery_crud->render();
$this->load->view('mobil.php', $output); ?>
Logout
</div>
</div>
</div>
</body>
</html>
My routes:
$route['default_controller'] = 'user';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['home'] = 'user/home';
What should I correct to make these functions work on this page? Thx :)
You must access your edit page via your controller/method manner
if your controller is user and it has a function edit with a param name $id, your accessing url will be:
http://subdomain.mysite.com/index.php/user/edit/1
or define new route for it:
$route['home/edit'] = 'user/edit';
or more clearly as
$route['home/edit/(:num)'] = 'user/edit/$1';
But you can get clean urls by following these steps:
First create a .htaccess file in your websites root folder with this code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
After that change:
$config['base_url'] = 'http://subdomain.mysite.com/';
and
$config['index_page'] = '';
After doing the above steps, you can access your urls without index.php in urls
for example:
http://subdomain.mysite.com/index.php/user/edit/1
will become
http://subdomain.mysite.com/user/edit/1
I have a controller with two functions as below
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('User_model');
}
public function index() {
$this->load->view('registration/index');
}
public function login() {
$this->load->view('registration/index');
}
and following in the header.php file
<li class="nav-item">
<a class="nav-link" href="<?php echo site_url("user/login")?>">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo site_url("user")?>">Register</a>
</li>
My problem is when I click on register button with site_url('user'), its working fine but when i click login button with site_ur('user/login') my css are not loaded. I have tried the same view for both the function. But later one is showing problem.
Can anybody help me what configuration mistake I did. My file structure of view folder is:
- views
-registration
-index.php
-index_script.php
templates
-header.php
-footer.php
-html_header.php
index.php has
<?php $this->load->view("templates/html_header");
$data = array();
$data["additional_script"] = $this->load->view("registration/index_scripts", array(), true);
$this->load->view("templates/footer", $data);
?>
html_header.php contains
<!-- include angular js -->
<script src="libs/angular/angular.min.js"></script>
<link href="libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/css/clean-blog.min.css" rel="stylesheet">
<?php $this->load->view("templates/header")?>
header.php
The URL you are using is incorrect. You must add <?php echo base_url(); ?> to the script src.
For eg: <script src="<?php echo base_url(); ?>libs/angular/angular.min.js"></script>
Maybe this can work.
I have two controllers in my project. The second controller do not displays in right way. If I open it with in browser line - thats ok, but if i pass it by the link in view its not ok. The second controller resembles on 1st.
Controller(s)
<?php
if ( ! defined('BASEPATH')) exit ('No direct script access allowed');
class Article extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
ini_set('display_errors',1);
error_reporting(E_ALL);
$this->load->view('header_view');
$this->load->view('menu_view');
$this->load->view('categories_view');
$this->load->model('mat_model');
$data = array();
$data['news'] = $this->mat_model->get_latest();
$data['latest'] = $this->mat_model->get_latest();
$this->load->view('useful_sites_view',$data);
$this->load->view('article_view',$data);
$this->load->view('footer_view');
}
}
?>
The view where I have a link:
<?php foreach ($news as $one):?>
<div id="right">
<div id="breadcrumb">Home » Somewhere</div>
<h1><?=$one['title']?></h1>
<p>
<div id="small_img"><?=$one['small_img']?></div>
<?=$one['description']?>
</p>
<div id=""> Читать далее...</div>
<span class="postinfo"> Posted by <?=$one['author']?> on
<?=$one['date']?></span>
<HR ALIGN="center" WIDTH="70%" SIZE="1px" COLOR="black">
</div>
<?php endforeach; ?>
I dont have so much reputation to browse images on the site, but i needs it so much, apologize for using otherwise resource
With line in browser:
With the link:
http://s020.radikal.ru/i710/1301/fd/76f313259454.jpg
With the browser line:
http://s020.radikal.ru/i713/1301/4e/a863cd18184d.jpg
Thanks.
In reply to the comment above...
<link rel="stylesheet" href="<?= base_url() ?>css/style.css">
is an absolute path.
Lets say that your base_url() is 'http://www.example.com/' so the above line will link to your css like so:
<link rel="stylesheet" href="http://www.example.com/css/style.css">
so no matter which page you're on, the CSS will always be linked to that css file.
On the other hand if you were using relative paths like this:
<link rel="stylesheet" href="/css/style.css">
on your site root, the css path would be correct. BUT on some other page, for example
http://www.example.com/somepage/testurl
your CSS would be linked like this:
<link rel="stylesheet" href="http://www.example.com/somepage/testurl/css/style.css">
which is obviously, wrong.
Try to google relative and absolute paths in html, that should make things a lot clearer.
Hey i am totally new in Codeigniter. In the Controllers folder I created a file named caller.php and I created a file home1.php in \Views. In root directory i created an image folder named \Images and also created a css folder named \css. In images Folder there are 6 picture. In css folder style.css file exist.
In caller.php i write
<?
class caller extends CI_Controller
{
function index()
{
$this->load->view('home1');
// what i have to write here lo load images....
}
}
In home1.php i write
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">
// what i have to write here to load images
</head>
<body>
<div id="outer">
<div id="container">
<div id="images">
<img src="new.jpg" width="960" height="400"/>
<img id="image1" src="1.jpg" />
<img id="image2" src="2.jpg" />
<img id="image3" src="3.jpg" />
<img id="image4" src="4.jpg" />
<img id="image5" src="5.jpg" />
</div>
<div id="slider">
1
2
3
4
5
</div>
...................................................
....................................................
</div>
</div>
</body>
</html>
Now for the above code how i load the images .Please experts help me.
if additional config's are needed please mention that.
As you're already using the url helper I suggest wrapping your image src attributes with base_url, such as:
<img src="<?php echo base_url('images/1.jpg'); ?>" />
And as mentioned in the other answer it's best (mandatory?) to capitalize the class name in your controller
class Caller extends CI_Controller { ...
First of all, you need to capitalize your class name.
class Caller extends CI_Controller {
public function index()
{
// method code goes here
}
}
Then, you need to link to those images with absolute links or with the CI URL helper: "/images/1.jpg" and so on.
How to use with the CI URL helper is detailed here : Helper
EDIT
Load the URL helper with this in your constructor method:
$this->load->helper('url');
You can create a URL like this:
echo base_url("blog/post/123");
That will make:
http://example.com/index.php/news/local/123
Or
http://example.com/news/local/123
If you've taken out the index.php in your config file.
Here's a class with the constructor that calls the URL helper:
class Caller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
// method code goes here
}
}
Make folder in root directory and code easily in views html file.
if directory name is directoryName and image name imageName.jpg
you can call like this.
<img src="directoryName/imageName.jpg">
You can do the same for as you did to Load the CSS files.
Create a folder in Root Directory. Create a sub folder(if you have Multisite)
then point your base_url in config file to your base path.
and then do the same
<img id="image1" src="<?PHP echo base_url(); ?>images/[sub-folder]/1.jpg" />
Only simple way
<img id="image1" src="<?php echo base_url('1.jpg'); ?>" />
That sit!!!