简体   繁体   English

Codeigniter模板引擎

[英]Codeigniter Template Engine

Assume i have controller with the class name " google " and it contains some data example 假设我有一个类名为“ google ”的控制器,它包含一些数据示例

// application/controller/google.php // application / controller / google.php

$data = array(
    'target' => 'earth',
    'percentage' => 70
);

and its view file is ' google_view.php ' // application/view/google_view.php 其视图文件为' google_view.php '// application / view / google_view.php

and in second controler with the calss name " msn " here i want to get the " google " controller data .. or i just want to include " google_view " file without passing the $data variable again 在第二个控制器中,名称为“ msn ”,我想获取“ google ”控制器数据..或者我只想包含“ google_view ”文件,而无需再次传递$data变量

I heard to use of setflash .. but the problem is what if user visit msn page without visiting google 我听说要使用setflash ..但问题是,如果用户在不访问Google的情况下访问msn页面,该怎么办

so is there any way to get google controller data? 所以有什么办法来获取谷歌控制器数据吗?

i also checked opencart cms & its an MVC framework in its controller we can call another controller like below.. in below code we can call header controller. 我还检查了opencart cms及其控制器中的MVC框架,我们可以像下面这样调用另一个控制器..在下面的代码中,我们可以调用标头控制器。

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header'
);

You're looking for HMVC features, which CodeIgniter doesn't really do. 您正在寻找HMVC功能,而CodeIgniter并没有真正做到这一点。 Take a look at this library which implements it in CI : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc . 看一下在CI中实现它的这个库: https : //bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc There's lots of resources on the net which explain HMVC vs MVC in more detail. 网上有很多资源可以更详细地解释HMVC与MVC。

If you're doing this sort of thing on any sort of scale, CodeIgniter might not be the best framework for your application - it would be worth looking at a few others. 如果您以任何规模进行此类操作,则CodeIgniter可能不是适用于您的应用程序的最佳框架-值得一提的是其他一些框架。 I'm using a lot of Laravel at the minute, which would work perfectly fine if you're just wanting to fetch the output of another controller (eg. in Laravel you just go $second_controller_output = Route::forward('GET','other/controller'); ). 我在此刻使用了很多Laravel ,如果您只是想获取另一个控制器的输出(例如,在Laravel中,您只需要$second_controller_output = Route::forward('GET','other/controller'); )。

Hope that helps! 希望有帮助!

Mmm ... I don't think you do that in CI but I'll suggest one idea ... 嗯...我不认为您会在CI中这样做,但我会建议一个主意...

Extend the Controller core class, then be sure to extend your new class in your application controller's constructors. 扩展Controller核心类,然后确保在应用程序控制器的构造函数中扩展新类。 Eg 例如

class MY_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->default_data_google = array(
            'target' => 'earth',
            'percentage' => 70
        );
    }

}

class Google extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $data = $this->default_data_google;
        $this->load->view('google_view', $data);
    }

}

//

.. ..

class Msn extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $data = $this->default_data_google;
        $this->load->view('google_view', $data);
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM