简体   繁体   中英

Show data from view in variable in layout in Joomla 3.1

Here below is the code from the view.html.php

class ><><><><><><><>< extends JViewLegacy
{
    public $data;

    // Overwriting JView display method
    function display($tpl = null) 
    {
        // Check for errors.
        if (count($errors = $this->get('Errors'))) 
        {
            JError::raiseError(500, implode('<br />', $errors));
            return false;
        }
        $data = $this->data;            // This is having array object

        // Display the view
        parent::display($tpl);
    }
}

Here below is the code in default.php

Result View

<?php 
        echo "<pre>";
            print_r($data);
        echo "</pre>";
?>

The data in default.php is not showing any data.

To assign values from view.html.php you should use something like this:

$this->data = $data;

And in default.php you should access $data by:

print_r($this->data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM