加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Codeigniter视图函数更改为$template

发布时间:2020-12-13 22:48:47 所属栏目:PHP教程 来源:网络整理
导读:我目前有以下功能,但我想使用 following将其更改为“模板”,但我不确定实现目标的最佳方法是: 这背后的原因是因为我需要在product_get_details函数中利用admin WYSIWYG片段append_metadata($this- load- view(‘fragments / wysiwyg’,array(),TRUE)). 码:
我目前有以下功能,但我想使用 following将其更改为“模板”,但我不确定实现目标的最佳方法是:

这背后的原因是因为我需要在product_get_details函数中利用admin WYSIWYG片段append_metadata($this-> load-> view(‘fragments / wysiwyg’,array(),TRUE)).

码:

public function ajax_product_get_details($product_id = NULL)
    {

    if(isset($_POST['id']))
        {
            $product_id = $_POST['id'];
        }

        $table = SITE_REF.'_ps_products';
        $data['product_details'] = $this->Ps_products_model->table_get_row($table,$product_id);
        $data['assoc_categories'] = $this->Ps_products_model->product_get_x_categories($product_id);
        $data['parent_categories'] = $this->Ps_products_model->categories_get_parent_list();
        $data['folders'] = $this->file_folders_m->get_folders();
        $table_man = SITE_REF.'_ps_products_manufacturers';
        $data['manufacturers'] = $this->Ps_products_model->table_get_all($table_man,'name','asc');

        $this->load->view('admin/ajax/admin_product_details',$data);

    }

指数功能:

public function index()
    {
      $this->template

        ->title($this->module_details['name'])          
        ->append_js('jquery/jquery.ui.nestedSortable.js')
        ->append_js('jquery/jquery.stickyscroll.js')
        ->append_metadata($this->load->view('fragments/wysiwyg',TRUE))
        ->append_js('module::admin.js')
        ->append_css('module::admin.css')
        ->append_css('module::custom.css')
        ->set('pages',$this->page_m->get_page_tree())
        ->set('folders',$this->file_folders_m->get_folders())
        ->build('admin/index');
    }

解决方法

@Youhan是对的.您可以从另一个视图加载视图.但他给出的参数是错误的.如果将第三个参数设置为true,则该函数将视图作为字符串返回.

所以你只需要在admin_product_details视图中添加这一行:

$this->load->view('fragments/wysiwyg');

编辑

你为什么不简单地使用你的模板? :

public function ajax_product_get_details($product_id = NULL)
{

    if(isset($_POST['id']))
    {
        $product_id = $_POST['id'];
    }

    $table = SITE_REF.'_ps_products';
    $data['product_details'] = $this->Ps_products_model->table_get_row($table,$product_id);
    $data['assoc_categories'] = $this->Ps_products_model->product_get_x_categories($product_id);
    $data['parent_categories'] = $this->Ps_products_model->categories_get_parent_list();
    $data['folders'] = $this->file_folders_m->get_folders();
    $table_man = SITE_REF.'_ps_products_manufacturers';
    $data['manufacturers'] = $this->Ps_products_model->table_get_all($table_man,'asc');

    $this->template
        ->title($this->module_details['name'])
        ->append_metadata($this->load->view('fragments/wysiwyg',TRUE))
        ->build('admin/ajax/admin_product_details',$data);

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读