我目前有以下功能,但我想使用 following 将其更改为"template"但我不确定实现目标的最佳方法是什么:
这背后的原因是因为我需要利用管理员所见即所得片段 append_metadata($this->load->view('fragments/wysiwyg', array(), TRUE))
在我的 product_get_details
函数中。
代码:
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');
}
最佳答案
@Youhan 说的对。您可以从另一个 View 加载一个 View 。但是他给的参数是错误的。如果将第三个参数设置为 true
,该函数将以字符串形式返回 View 。
因此,您只需在 admin_product_details
View 中添加这一行:
$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);
}
关于php - Codeigniter View 函数更改为 $template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16828231/