4

I currently have the following function but I would like to change it into a "template" using the following but I am not sure what the best way to achieve my goal is:

The reason behind this is because I need to take advantage of the admin WYSIWYG fragment append_metadata($this->load->view('fragments/wysiwyg', array(), TRUE)) within my product_get_details Function.

Code:

    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);

    }

Index Function:

   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');
    }
Jess McKenzie
  • 8,345
  • 27
  • 100
  • 170

1 Answers1

1

@Youhan is right. You can load a view from another view. But the parameters he gives are wrong. If you set the third parameter to true, the function will return the view as a string.

So you just have to add this line in your admin_product_details view:

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

EDIT

Why don't you simply use your template? :

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);

}
Lebugg
  • 303
  • 1
  • 8
  • What should I be setting for the http://d.pr/i/UXnV or do we need to some how get it working via __construct? Its still not working – Jess McKenzie Jun 05 '13 at 19:10
  • What do you mean by not working? Does it throw an error or just returns nothing (when you put the third parameter to TRUE)? – Lebugg Jun 06 '13 at 08:21
  • I have put this `append_metadata($this->load->view('fragments/wysiwyg', array(), TRUE))` into my code function along side the above but im still not getting any wysiwyg – Jess McKenzie Jun 06 '13 at 18:23
  • Why don't you use `$this->template` in `ajax_product_get_details()`? – Lebugg Jun 07 '13 at 09:01
  • That was my plan but I cant seem to get the right build can you provide an example – Jess McKenzie Jun 07 '13 at 21:24
  • It depends on your wysiwyg content? What's in it? Does it need to be place in a special place: tag for example? And since you are sending it via Ajax, you may have to add a class to one of your DOM element after request response. – Lebugg Jun 10 '13 at 13:14
  • Its just text no special requirements - ajax is not doing the processing – Jess McKenzie Jun 10 '13 at 19:54
  • I thought so because of your function name. – Lebugg Jun 11 '13 at 08:34
  • No I have been bypassing it - I took over the code and just continued using the naming - there is no need for it as the controller is using $_POST – Jess McKenzie Jun 11 '13 at 18:23
  • I have tried your statement and it loaded the header and footer that I do not want. Would I need to specify the CSS etc within the template I am building? – Jess McKenzie Jun 12 '13 at 05:05