Cómo obtengo la ruta de base del proyecto en CodeIgniter
He creado una carpeta como usuario en el directorio raíz.
Mi ruta base del proyecto es:
/var/www/myproject/
Cuando quiero acceder a la ruta base como RUTA BASE desde un controlador, se muestra:
/var/www/myproject/system/
Pero quiero que el camino sea:
/var/www/myproject/
Soy nuevo en CodeIgniter. ¿Cómo puedo establecer este camino?
6 answers
Utilice FCPATH en lugar de BASEPATH para ver más este enlace.
Codeigniter-obtener dinámicamente la ruta relativa / absoluta fuera de la carpeta de la aplicación
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
2017-05-23 10:31:14
Use base_url()
echo $baseurl=base_url();
Si necesita pasar url a una función, use site_url()
echo site_url('controller/function');
Si necesita la ruta raíz entonces FCPATH
..
echo FCPATH;
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-06-19 10:14:05
Las siguientes son las constantes integradas que puede usar según sus requisitos para obtener las rutas en Codeigniter :
EXT: The PHP file extension
FCPATH: Path to the front controller (this file) (root of CI)
SELF: The name of THIS file (index.php)
BASEPATH: Path to the system folder
APPPATH: The path to the “application” folder
Gracias.
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
2017-10-11 11:14:59
Codeigniter tiene una función que recupera su ruta base que es:
FCPATH and BASEPATH i recommand use FCPATH.
Para tu url base usa:
<?=base_url()?>
Si su etiqueta corta php está desactivada
<?php echo base_url(); ?>
Por ejemplo: si desea vincular los archivos css que está en su ruta base
<script src='<?=base_url()?>js/jquery.js' type='text/javascript' />
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
2014-06-29 10:30:29
Obviamente te refieres al baseurl. En caso afirmativo:
Url base: URL a la raíz de CodeIgniter. Por lo general, este será su URL base | / CON una barra al final.
Root en codeigniter significa específicamente que la posición en la que puede agregar su controlador a su url.
Por ejemplo, si la raíz es localhost/ci_installation/index.php/
, entonces para acceder al controlador mycont
debe ir a localhost/ci_installation/index.php/mycont
.
Entonces, en lugar de escribir un enlace tan largo, puede (después de cargar " url" helper ), reemplace el término localhost/ci_installation/index.php/
por base_url()
y esta función devolverá la misma cadena url.
NOTA: si no has agregado index.php/
a tu base_url
en tu config.php
, entonces si usas base_url()
, devolverá algo así localhost/ci_installation/mycont
. Y eso no funcionará, porque tienes que acceder a tus controladores desde index.php
, en lugar de eso puedes colocar un archivo .htaccess
en tu posición de instalación de codeigniter. Hacer frente a que el siguiente código a la misma:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /imguplod/index.php/$1 [L]
Y debería funcionar :)
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
2015-09-30 17:33:29
Cambie su controlador predeterminado que está en el archivo de configuración.
Es decir : configuración/rutas.php
$route['default_controller'] = "Your controller name";
Espero que esto ayude.
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-06-19 10:15:50