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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4320820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:39:45  来源:igfitidea点击:

Fatal error: Call to undefined function site_url()

phpfunctioncodeigniterviewcontroller

提问by student

I am using the CodeIgniter framework for PHP. I have created a view named "login.php". Once I

我正在使用 PHP 的 CodeIgniter 框架。我创建了一个名为“login.php”的视图。有一次,我

created the view, I then loaded the view inside of a function named "index" which is located

创建了视图,然后我将视图加载到名为“index”的函数中,该函数位于

inside a class named "CCI" that extends the Controller but I keep receiving this error: Fatal

在扩展控制器的名为“CCI”的类中,但我不断收到此错误:致命

error: Call to undefined function site_url() in C:\wamp\www\FinalP_CCI_Clone\system

错误:调用 C:\wamp\www\FinalP_CCI_Clone\system 中未定义的函数 site_url()

\application\views\login.php on line 12. I don't understand the issue I an having because the

\application\views\login.php 第 12 行。我不明白我遇到的问题,因为

welcome page loads fine and my second function inside of the "CCI" class loads fine as well.

欢迎页面加载良好,我在“CCI”类中的第二个函数也加载良好。

Here is some of the code:

这是一些代码:

Controller Files:

控制器文件:

function CCI()
{
    parent::Controller();
}

function index()
{
    $this->load->view('login');
}

function test()
{
    echo "Testing Data";
}

}

}

/* End of file login.php / /Location: ./system/application/controllers/cci.php */

/* 文件login.php 结束//位置:./ system /application /controllers /cci.php */

class Welcome extends Controller {

类欢迎扩展控制器{

function Welcome()
{
    parent::Controller();   
}

function index()
{
    $this->load->view('welcome_message');
}

function test()
{
    echo "Testing Data";
}

}

}

/* End of file welcome.php / /Location: ./system/application/controllers/welcome.php */

/* 文件结束welcome.php //位置:./system/ application /controllers /welcome.php */

回答by netcoder

You have to load the helper. The function site_url()is provided by the urlhelper, as described here.

您必须加载助手。该功能site_url()url帮助程序提供,如此处所述

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

回答by Dharmana

You can try this:

你可以试试这个:

  1. First Load the URL Helper with:

    • $this->load->helper('url');or set the following value in application/config/autoload.php
    • $autoload['helper'] = array('url');
  2. Then you can show the site url with:
  1. 首先加载 URL Helper:

    • $this->load->helper('url');或设置以下值 application/config/autoload.php
    • $autoload['helper'] = array('url');
  2. 然后您可以使用以下内容显示网站网址:

Note: Results depends on values stored in application/config/config.php

注意:结果取决于存储在 application/config/config.php