4

我目前有以下功能,但我想使用以下方法将其更改为“模板”,我不确定实现目标的最佳方法是:

这背后的原因是因为我需要利用 append_metadata($this->load->view('fragments/wysiwyg', array(), TRUE))我的product_get_detailsFunction 中的 admin 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, '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', array(), 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');
    }
4

1 回答 1

1

@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, 'name', 'asc');

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

}
于 2013-06-05T15:28:03.300 回答