致命错误:在第 5 行调用 C:\wamp\www\Test-CI\application\views\layout.php 中未定义的函数 base_url()

2022-08-30 11:04:04

你好,我是CodeIgniter和PHP的新手,我正在尝试在firs时间内设置它,但它给出了以下错误。

致命错误:调用未定义的函数 base_url()

  1. C:\wamp\www\Test-CI\application\views\layout.php第 5 行
     

  2. {主}( ) 在 ..\索引.php:0require_once('C:\wamp\www\Test-CI\system\core\CodeIgniter.php' ) IN ..\索引.php:202

  3. call_user_func_array ( ) IN ..\CodeIgniter.php:359

  4. Home->index( ) IN ..\CodeIgniter.php:0

  5. CI_Loader->view( ) IN ..\首页.php:17

  6. CI_Loader->_ci_load( ) IN ..\加载器.php:419

  7. include('C:\wamp\www\Test-CI\application\views\layout.php' ) IN ..\加载器.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>

答案 1

您必须加载 url 帮助程序才能访问该函数。您可以添加

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

控制器中的某个位置。

或者,要使其在任何地方自动加载,请确保应用程序/配置/自动加载中的行.php如下所示

$autoload['helper'] = array('url');

在该数组中具有(如上所示)。'url'


答案 2

只需添加

$autoload['helper'] = array('url');

在自动加载中.php配置文件中


推荐