I'm loading bootstrap this way on my view page :
<link rel="stylesheet" href="<? echo base_url('assets/css/bootstrap.min.css')?>">
autoload: $autoload['helper'] = array('url');
configs: $config['base_url'] = 'http://localhost/helloby/';
Below is the path of the controller:
http://localhost/helloby/index.php/login/home
But when I copy the same code at welcome_message view bootstrap loads normally. I don't know why it's happening.
Try using site_url() instead of base_url()
base_url returns the url without index.php
Check if you are loading the bootstrap css in every view, you cant just load it in one view and expect that all other views know about it.
Common way of doing things like this is to create header and footer files that are shared between all views.
I solved the problem, I was reading an e-book of best practice of Codeigniter and the call of bootstrap was a little bit different.
This way : href="<?=base_url('/assets/css/bootstrap.min.css')?>
and working fine!
I am trying to load a view from a controller file. If I reference my class in the view everything is fine, however if I reference a method from that class my css does not load.
Here is a simple example:
Controller file:
<?php
class Example extends CI_Controller
{
public function index ()
{
$this->load->view('myview');
}
}
In the view file this works fine:
<li>EXAMPLE</li>
But, this does not:
<li>EXAMPLE</li>
I also tried to use the site_url() function but the result was the same.
Note: I have loaded the URL helper.
Have you change your .htaccess file to remove index.php in url? then
<li>EXAMPLE</li>
it will not work.
you can try to add
<base href="<?php echo cdn_url()?>" />
into the tag <head></head>
Make sure that you have configured your config to php file properly. Then See take a look and make sure that have you removed index.php from url? if yes then remove index from every url you are targeting.I Hope it will work.
In config.php
$config['base_url'] = 'http://localhost/{your_project_folder}/';
I'm new to Codeigniter and i have a problem in page routing. I have a button placed in my first page
<center>Start</center>
I have a page in my view folder. I want to direct to this page when i click my button. How can i navigate to my page in view folder on button click.
My base url
$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';
Thanks in advance
As you are using codeigniter, you could simply name the function in the contorller that would load the page you want.
<center>Start</center>
or depending on your configurations:
<center>Start</center>
in the controllerName and the functionName:
// Other code ...
$this->load->view('viewFileName');
First load url_helper by
$this->load->helper('url');
Or in your autoload.php set
$autoload['helper'] = ['url'];
Then
Start
Note: Use site_url() instead of base_url(), base_url() suited
for src like
<img src="<?php echo base_url()" /> ....
First you need enable url library
$this->load->helper('url');
then test base_url(); function
Returns your site base URL, as specified in your config file. Example:
echo base_url();
And Calling view page, Suppose your file name is home.php
<?php
class Example extends CI_Controller {
function index()
{
$this->load->view('home');
}
}
?>
Your base url is incorrect
replcae
$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';
to'
$config['base_url'] = 'http://localhost/CodeIgniter/';
then
<center>Start</center>
Read this tutorial for more http://w3code.in/2015/10/codeigniter-installation-beginner-guide/
hi i am new in cakephp 2x.
i am working on the backend and i did some insert update and delete in it.
i also did the pagination in the cakephp with ajax. now i want to create the popup for the seatch functionality. i want to use the modalbox.js for that prototype.js and scriptaculas.js
but when i need this all the ajax is stopped working. i dont know why.
i read the just insert as helper so i write this code in the controller
public $helpers = array('Html', 'Form','Session','Ajax','Js'=> array('Prototype','Scriptaculous'));
now tell me what to do the next ?
i have included the helper but from where i can found this helper file ?
i just want to open the popup file
Thanks in advance
The ajax stop working, may be because of the compatibility factor of those js files. But you can't enter js files as helper files. Only helper files can be on helper folder under view folder.
In my web application using codeigniter. I am trying to use base_url() function but it shows empty results. I have also used autoload helper through autoload file, but then too it doesn't seem to work. Also I had defined base constants but all in vain.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
<script type="text/javascript">
//<![CDATA[
base_url = '<?= base_url();?>';
//]]>
</script>
</head>
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (on or around line 67):
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();
Remember also that the value returned is the site's base url as provided in the config file. CodeIgniter will accomodate an empty value in the config file as well:
If this (base_url) is not set then CodeIgniter will guess the protocol, domain and path to your installation.
application/config/config.php, line 13
If you want to use base_url(), so we need to load url helper.
By using autoload $autoload['helper'] = array('url');
Or by manually load in controller or in view $this->load->helper('url');
Then you can user base_url() anywhere in controller or view.
First of all load URL helper. you can load in "config/autoload.php" file and add following code
$autoload['helper'] = array('url');
or in controller add following code
$this->load->helper('url');
then go to config.php in cofig folder and set
$config['base_url'] = 'http://urlbaseurl.com/';
hope this will help
thanks
Check if you have something configured inside the config file /application/config/config.php e.g.
$config['base_url'] = 'http://example.com/';
I think you haven't edited codeigniter files to enable base_url(). you try to assign it in url_helper.php you also can do the same config/autoload.php file. you can add this code in your autoload.php
$autoload['helper'] = array('url');
Than You will be able to ue base_url() like this
<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
Apart from making sure you have set config/autoload.php:
$autoload['helper'] = array('url');
Change application/config/config.php from:
$config['base_url'] = 'http://example.com/';
Become a dynamic base url:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https": "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
And using the host from php to run it on local, below is just an example port.
php -S localhost:2000
If you don't want to use the url helper, you can get the same results by using the following variable:
$this->config->config['base_url']
It will return the base url for you with no extra steps required.
Load url helper in controller
$this->load->helper('url');
Anything if you use directly in the Codeigniter framework directly, like base_url(), uri_string(), or word_limiter(), All of these are coming from some sort of Helper function of framework.
While some of Helpers may be available globally to use just like log_message() which are extremely useful everywhere, rest of the Helpers are optional and use case varies application to application. base_url() is a function defined in url helper of the Framework.
You can learn more about helper in Codeigniter user guide's helper section.
You can use base_url() function once your current class have access to it, for which you needs to load it first.
$this->load->helper('url')
You can use this line anywhere in the application before using the base_url() function.
If you need to use it frequently, I will suggest adding this function in config/autoload.php in the autoload helpers section.
Also, make sure you have well defined base_url value in your config/config.php file.
This will be the first configuration you will see,
$config['base_url'] = 'http://yourdomain.com/';
You can check quickly by
echo base_url();
Reference: https://codeigniter.com/user_guide/helpers/url_helper.html
Question -I wanted to load my css file but it was not working even though i autoload and manual laod why ? i found the solution =>
here is my solution :
application>config>config.php
$config['base_url'] = 'http://localhost/CodeIgniter/'; //paste the link to base url
question explanation:
" >
i had my bootstrap.min.css file inside assets/css folder where assets is root directory which i was created.But it was not working even though when i loaded ?
1. $autoload['helper'] = array('url');
2. $this->load->helper('url'); in my controllar then i go to my
I encountered with this issue spending couple of hours, however solved it in different ways. You can see, I have just created an assets folder outside application folder. Finally I linked my style sheet in the page header section. Folder structure are below images.
Before action this you should include url helper file either in your controller class method/__constructor files or by in autoload.php file. Also change $config['base_url'] = 'http://yoursiteurl'; in the following file application/config/config.php
If you include it in controller class method/__constructor then it look like
public function __construct()
{
$this->load->helper('url');
}
or If you load in autoload file then it would looks like
$autoload['helper'] = array('url');
Finally, add your stylesheet file.
You can link a style sheet by different ways, include it in your inside section
-><link rel="stylesheet" href="<?php echo base_url();?>assets/css/style.css" type="text/css" />
-> or
<?php
$main = array(
'href' => 'assets/css/style.css',
'rel' => 'stylesheet',
'type' => 'text/css',
'title' => 'main stylesheet',
'media' => 'all',
'index_page' => true
);
echo link_tag($main); ?>
-> or
finally I get more reliable code cleaner concept. Just create a config file, named styles.php in you application/config/styles.php folder.
Then add some links in styles.php file looks like below
<?php
$config['style'] = array(
'main' => array(
'href' => 'assets/css/style.css',
'rel' => 'stylesheet',
'type' => 'text/css',
'title' => 'main stylesheet',
'media' => 'all',
'index_page' => true
)
);
?>
call/add this config to your controller class method looks like below
$this->config->load('styles');
$data['style'] = $this->config->config['style'];
Pass this data in your header template looks like below.
$this->load->view('templates/header', $data);
And finally add or link your css file looks like below.
<?php echo link_tag($style['main']); ?>
This All Directly Access Function Will Be Loaded Through Helper Class Only.
Like URL, Security, File all Are Helpers and You can Also Load Custom Helpers.
config/autoload.php
$autoload['helper'] = array('url', 'file', 'authorization', 'custom');