如何使用Codeigniter加载基本视图


How to load a basic view using Codeigniter

我正试图从我的控制器加载一个名为index.php的视图,该视图称为anish.php。以下是目前我为控制器设置的内容:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Anish extends Public_Controller
{
public function __construct()
{
parent::__construct();
// Load the required classes
$this->load->model('anish_m');
$this->lang->load('anish');
$this->template
  ->append_css('module::anish.css')
  ->append_js('module::anish.js');
}
public function index()
{
$this->template
  ->set('anish')
  ->build('index');
}
}

这是我在index。php中的内容:

Hello world

我感谢任何人的帮助。谢谢你

如果你想在index函数中加载index.php视图请执行如下操作

public function index()
{
    $this->load->view('index');//index is the name of the view file minus the .php extension
}

如果你想传递任何数据到你的视图,然后使用第二个参数。例如

public function index()
{
    $aData['hello'] = 'Hello World!';
    $this->load->view('index', $aData);//In the view you would then do <?php echo $hello; ?>
}

当你调用一个视图时,它会立即回显它。如果你想把视图的内容保存到一个变量中,你可以传递TRUE作为第三个参数

public function index()
{
    $aData['hello'] = 'Hello World!';
    $this->load->view('index', $aData, TRUE);
}

我不知道你到底是什么问题。但要从控制器的任何方法加载视图(比如index.php),你可以调用:

$this->load->view('index');

ANSWER:对于URL,它对模块是区分大小写的。我只需要把第一个字母大写。谢谢大家的帮助。