【问题标题】:codeignither HMVC version 3.0.6 view not loadingcodeigniter HMVC 3.0.6 版视图未加载
【发布时间】: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


【解决方案1】:
 echo Modules::run('templates/two_col', $data);
        #$this->load->module('templates');

我很确定将这些代码一起替换会起作用。

因为 php 是一种解释型编程语言。如果检测到 ex 的错误,PHP 会逐行加载。在第 5 行它不编译其余行。 More information for interpreted lang. 以及在您的代码中,您在加载 lib 之前实现了 lib 函数

【讨论】:

  • 欢迎来到 Stack Overflow!尽管此代码可能有助于解决问题,但它并没有解释 为什么 和/或 如何 回答问题。提供这种额外的背景将显着提高其长期教育价值。请edit您的答案添加解释,包括适用的限制和假设。
  • 因为 php 是一种解释型编程语言。如果检测到 ex 的错误,PHP 会逐行加载。在第 5 行它不编译其余行。 More information for interpreted lang.
  • 在你的代码中你在加载 lib 之前实现了 lib 函数。
  • Ahmetcan,我认为这些 cmets 应该作为 edit 添加到您的答案中。
猜你喜欢
  • 2014-02-18
  • 2014-03-25
  • 1970-01-01
  • 2013-08-31
  • 1970-01-01
  • 2013-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-08-07
相关资源
最近更新 更多