【发布时间】:2016-10-04 05:40:39
【问题描述】:
以下是我在 codeignither HMVC 中制作的模板的控制器。我正在尝试将此模板模块加载到我的任务模块中,但由于某种原因,它不会加载到模板模块中,但数据会加载到我的任务控制器中。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class templates extends MX_Controller
{
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function one_col($data)
{
$this->load->view('one_col',$data);
}
public function two_col($data)
{
$this->load->view('two_col',$data);
}
public function admin($data)
{
$this->load->view('admin', $data);
}
public function index()
{
echo "Hello world";
}
}
下面的这段代码是我的任务控制器,当我在链接http://localhost:81/hmvc/index.php/tasks 中运行它时它工作正常但是当我尝试运行模板视图“two_col”http://localhost:81/hmvc/index.php/templates/two_col 时
在模板中使用此代码
<?php $this->load->view($module.'/'.$view_file); ?>
下面的任务模块控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class tasks extends MX_Controller
{
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->model('mdl_tasks');
$data['query'] = $this->mdl_tasks->get('priority');
#$this->load->view('display', $data);
$data['view_file'] = "display";
$data['module'] = "tasks";
echo Modules::run('templates/two_col', $data);
#$this->load->module('templates');
#$this->templates->two_col($data);
}
}
【问题讨论】:
-
您看到的那些错误是正确的,因为您正在调用没有 $data 的模板方法,这些错误正在说明。您的“调用”中缺少参数 $data 且未定义。
标签: codeigniter-3 hmvc