你好我是CodeIgniter和PHP的新手,我试图在第一次设置它,但它给出了以下错误.
致命错误:调用未定义的函数base_url()
- 第5行的C:\ wamp\www\Test-CI\application\views\layout.php
{main}()IN ..\index.php:0 require_once('C:\ wamp\www\Test-CI\system\core\CodeIgniter.php')IN ..\index.php:202
call_user_func_array()IN ..\CodeIgniter.php:359
CodeGo.net> index()IN ..\CodeIgniter.php:0
CI_Loader-> view()IN ..\home.php:17
CI_Loader - > _ ci_load()IN ..\Loader.php:419
include('C:\ wamp\www\Test-CI\application\views\layout.php')IN ..\Loader.php:833
我的代码:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Galleriffic | Custom layout with external controls</title>
<link rel="stylesheet" href="<?php base_url(); ?>/assets/css/basic.css" type="text/css" />
<link rel="stylesheet" href="<?php base_url(); ?>/assets/css/galleriffic-5.css" type="text/css" />
<!-- <link rel="stylesheet" href="<?php base_url(); ?>/assets/css/white.css" type="text/css" /> -->
<link rel="stylesheet" href="<?php base_url(); ?>/assets/css/black.css" type="text/css" />
<script type="text/javascript" src="<?php base_url(); ?>/assets/js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="<?php base_url(); ?>/assets/js/jquery.history.js"></script>
<script type="text/javascript" src="<?php base_url(); ?>/assets/js/jquery.galleriffic.js"></script>
<script type="text/javascript" src="<?php base_url(); ?>/assets/js/jquery.opacityrollover.js"></script>
<!-- We only want the thunbnails to display when javascript is disabled -->
<script type="text/javascript">
document.write('<style>.noscript { display: none; }</style>');
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
com*_*857 155
您必须加载url帮助程序才能访问该功能.要么你添加
$this->load->helper('url');
Run Code Online (Sandbox Code Playgroud)
控制器中的某个地方.
或者,要在任何地方自动加载它,请确保application/config/autoload.php中的行看起来像
$autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)
具有'url'
该阵列中(如上所示).
Har*_*esh 17
加上
$autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)
在配置文件中的autoload.php中
Dav*_*ger 12
您需要在控制器中的某个位置加载视图之前加载帮助程序.
但我想在这里你想要使用这个功能 site_url()
在加载视图之前,基本上在控制器中方法的任何位置,将其添加到您的代码中:
$this->load->helper('url');
然后使用该功能 site_url()
.
小智 6
只有三种方法可以解决。将以下代码粘贴到此路径 application/config/autoload.php 中。
他们中的大多数我都用这个
require_once BASEPATH . '/helpers/url_helper.php';
Run Code Online (Sandbox Code Playgroud)
这很好,但有一段时间,它失败了
$autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)
我从不使用它,但我知道它有效
$this->load->helper('url');
Run Code Online (Sandbox Code Playgroud)
在codeigniter项目中加载其他文件(css,js)和文件夹(图像)
我们必须遵循两个简单的步骤:
1.在codeigniters文件夹中创建文件夹public(可以给出任何名称),将你的bootstrap文件css和js文件夹放在side public folder中.https://i.stack.imgur.com/O2gr6.jpg
2.现在我们必须使用两行代码1.load-> helper('url'); ?> 2.
转到您的视图文件
将第一行放入加载基本URL
<?php $this->load->helper('url'); ?>
Run Code Online (Sandbox Code Playgroud)
其次在你的html head标签中放了这个
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/public/css/bootstrap.css">
Run Code Online (Sandbox Code Playgroud)
现在你可以享受你的codeigniter中的引导程序