2

I hardly know any OOP PHP so I don't know how to properly pass variables, especially in EE.

I am working in a Module, and I have a function that passes my modules results to a .php file that has the table to show the results in the modules panel. I want to pass a variable "$config" to that file so I make a if/else statement.

Here is the function that passes my results to the file, that I need to pass the "$config" variable to create my if/else.

public function outputBrowser($results)
{
    // $rows = array();
    // print_r($results);
    // die();


    $this->EE->load->add_package_path($this->report_path);
    return $this->EE->load->view('output_browser', array("results" => $results), TRUE);

}

1 Answer 1

2

Alas you don't mention where you get $config from. I've assumed it's a global class variable below.

public function outputBrowser($results) {
    $data = array(
        "results" => $results,
        "config"  => $this->config
    );

    $this->EE->load->add_package_path($this->report_path);
    return $this->EE->load->view('output_browser', $data, TRUE);
}

The idea of a view file is that it contains minimal PHP code and ideally just view output. So it's good practice to prep anything before you send it to the view, for example, let's say you want to check if the config has been set:

    $data = array(
        "results"    => $results,
        "config"     => $this->config,
        "config_set" => (empty($this->config) ? false : true
    );

Then in the view template you can just do:

<?php if (config_set) : ?>
    do stuff <?php echo config; ?>
<?php endif; ?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.