Cómo obtener la url base en CodeIgniter 2.*


En la configuración.php

$config['base_url'] = 'http://localhost/codeigniter/';

A la vista

<link rel="stylesheet" href="<?php base_url(); ?>css/default.css" type="text/css" />

=> Error: Call to undefined function base_url(); Ayúdame

Author: Usman, 2011-09-21

5 answers

Para usar base_url() (taquigrafía), tienes que cargar el URL Helper primero

$this->load->helper('url');

O puede cargarlo automáticamente cambiando application/config/autoload.php

O {[12] } simplemente use

$this->config->base_url();

Lo mismo se aplica a site_url().

También puedo ver que te falta echo (aunque no es tu problema actual), usa el código a continuación para resolver el problema

<link rel="stylesheet" href="<?php echo base_url(); ?>css/default.css" type="text/css" />
 93
Author: Usman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-28 14:06:03

Sé que esto es muy tarde, pero es útil para los novatos. Podemos atuload url helper y estará disponible en toda la aplicación. Para esto en application \ config\autoload.php modificar de la siguiente manera -

$autoload['helper'] = array('url'); 
 9
Author: KutePHP,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-28 11:07:34

Necesita cargar el ayudante de URL para usar base_url(). En su controlador, haga:

$this->load->helper('url');

Entonces, en su opinión, puede hacer:

echo base_url();
 7
Author: birderic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-21 17:50:03

Simplemente cargue la clase auxiliar

$this->load->helper('url');

Eso es todo.

 4
Author: Mischa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-27 08:02:45

Es necesario añadir url helper en config / autoload

$autoload['helper'] = array('form', 'url', 'file', 'html'); <-- Like This

Entonces puedes usar base_url o cualquier tipo de url.

 1
Author: Sabbir,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-11 14:18:08