Search code examples
phphtmlphpstorm

PHPStorm - Suggestions in included HTML


I can not see suggestion for variable $data in Default.phtml if I include HTML file Default.phtml from class Code_Controller.php method. Here is a code example.

Code_Controller:

abstract class Core_Controller{
    protected $template;

    public function display(){
        $data['title']  = 'Title of site';

        if(Core_Config::$is_admin){
            require_once ADMIN_TEMPLATES_PATH . $this->template . '.phtml';
        }else{
            require_once PUBLIC_TEMPLATES_PATH . $this->template . '.phtml';
        }
    }
}

Default.phtml

<!DOCTYPE html>
<html>
<head>
    <title><?php echo $data['title'] ?></title>
</head>

<body>
    The content of the document......
</body>

</html>

Have anybody some idea?

Thanks for advice.


Solution

  • Standard approach in such case: use PHPDoc and declare that variable there (at the top of the file), e.g.

    <?php
    /** @var array $data */
    ?>
    ...HTML CODE HERE...