Hello Every one i have samll Problem Here iam using codegniter and i have template that i use in all my views in some page i afound that i can use grocery crud as it will make it easer to show and it will give better look , as iam using to show table in one page i need to add the total of the amont in that table so creat model and store the result in varbile whene i show that var in the view page it show in the header of the page .here is my code
this the code for MY_controler

  protected function render($template='main') {
        //save the controller and action names in session
        // i will add here the loginig function if its logeed it will work 
        // else it will send hime to loging page i will make it latter 
        // comments by samoual shingrai 
        if ($this->save_previous_url) {
            $this->session->set_flashdata('previous_controller_name', $this->previous_controller_name);
            $this->session->set_flashdata('previous_action_name', $this->previous_action_name);
        }
        else {
            $this->session->set_flashdata('previous_controller_name', $this->controller_name);
            $this->session->set_flashdata('previous_action_name', $this->action_name);
        }

        $view_path = $this->controller_name . '/' . $this->action_name . '.php'; //set the path off the view
        if (file_exists(APPPATH . 'views/' . $view_path)) {
            $this->data['content'] .= $this->load->view($view_path, $this->data, true);  //load the view
        }

        $this->load->view("layouts/$template.tpl.php", $this->data);  //load the template
    }

and the secound is the code for the template

        <div id="content">
            <?php echo $content;?>
        <?php
        echo @$output;

        ?>

        </div>

i show 2 value Content and output->for grocery crud

in the controler

function _example_output($page_set = null, $output = null) {
        $this -> load -> view($page_set, $output,FALSE);
    }

    function index() {
        $this -> _example_output((object) array('output' => '', 'js_files' => array(), 'css_files' => array(), 'data' => array()));


    }

and then in my function

$crud -> where('client_id', $clientid);     
        $crud -> set_relation('client_id', 'client', 'name');
        $crud -> set_relation('store_id', 'store', 'stname');
        $crud -> unset_delete();
        $crud -> unset_edit();
        $crud->unset_add();
         $output = $crud -> render();
        $output->total=$this->client_model->client_account_total($_POST["T1"]);
        // as you see i store the total  
             $page_set='clients/client_account';
     $this -> _example_output($page_set, $output,true);

        $this->render();

in the view page

<html>
<div id="total">
  <label id="total">AVAILABLE BALANCE = </label>
  <span><?php echo $total; ?></span>

</div>
</html>

so every thing is working fine but the result is not where it suppse to show in the $content or the $ourput Its showing in the header of the template .
any suggestion

the result is not where it suppse to show in the $content or the $ourput Its showing in the header of the template

I'm not sure I've understood your request, it seems some code is missing. I suppose the view page above is not the template page but the one accessed by:

$this->data['content'] .= $this->load->view($view_path, $this->data, true);

Correct? If yes, the template:

<div id="content">
    <?php echo $content;?>
<?php
echo @$output;
?>
</div>

Will include the entire "view page" and so you should get something like this:

<div id="content">
    <html>
    <div id="total">
      <label id="total">AVAILABLE BALANCE = </label>
      <span><?php echo $total; ?></span>
    </div>
    </html>
</div>

Is it this the problem you were talking about?

Are you loading other contents through $this->data['content']? I see you're using .= this will concatenate strings, so can you show how this starts?

Another problem is here:

function index() {
    $this -> _example_output((object) array('output' => '', 'js_files' => array(), 'css_files' => array(), 'data' => array()));
}

It seems wrong to me, because the _example_output() method expects two arguments:

function _example_output($page_set = null, $output = null) {
    $this -> load -> view($page_set, $output,FALSE);
}

The index() method, instead is sending only the first argument which should be a string, not an array (i.e. the second argument), since both can be NULL you have to declare the first argument. In pseudo code:

func(NULL, (object) array('value1', 'valueN'))

In your case it becomes:

function index() {
    $this -> _example_output(NULL, (object) array('output' => '', 'js_files' => array(), 'css_files' => array(), 'data' => array()));
}

But it doesn't makes sense anyway, because the load->view() method will fails because of the NULL, here you must define a default view page, as in the crud function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.