Notification about undefined variable in view with MVC

Hi people!

I using phpStorm with codeigniter, when i open a view program, the phpStorm indicates error when variable is defined in controller.

Does anybody know how to solve this?


1
2 comments

Hi there,

How it's defined in controller?

In general, IDE does not know how CodeIgniter works, how it defines variables and (in general) from what action that particular view/template will be called (rendered). Therefore, the common way to denote such variables is to typehint them in your view/template file (in PHP block, obviously, usually the very first at the top), e.g.

<?php
/** @var MyType $myVariable */
?>
Your HTML/whatever template below...

 

1

The variables transmitted to the view are defined in the controller via an associative array called $data like this:

Controller : $data["greeting"]="Hello"; $this->load->view('my_view', $this->data);

View : echo $greeting; // will display Hello.

There is a CodeIgniter plugin available for PhPStorm but apparently it doesn't help much to clear undefined variable errors in views code inspection when variables are defined in the controller using the $data array.

0

Please sign in to leave a comment.