Can you help me on this one. I'm new in CodeIgniter and PhpStorm, I'm having a problem. The PhpStorm IDE is showing an error, even though the code works fine (the Persons
(controller) class can't find the Person
(model) class).
$data['persons']=$this->**person**->get_person();
= on this syntax from Persons
class, there is a message "Field person
not found in class Persons
".
Can you enlighten me on how to resolve this, but actually the output is good and it retrieves the data without issue just a warning message in Persons
class.
The person
property ($this->property
) is not explicitly declared as it is created and accessed via PHP's magic methods.
PhpStorm has no special support for CodeIgniter framework and cannot guess where $this->person
is coming from and what type it is.
But you can help IDE -- just a small PHPDoc comment before the actual class -- using @property tag.
/**
* @property Person $person Optional description
*/
class Persons extends CI_Controller {
...and oh magic -- it works:
The answer from LazyOne did not work for me initially. After some testing I found out that my issue was upper/lower case related on how you declare the property in PHPDoc - hopefully the following observations can help someone else. This is what I have to declare my model class:
class Custom extends CI_Model {}
In my controller I load and use the model for example the following way:
$this->load->model('Custom')
$table = $this->Custom->get();
Now for phpStorm to pick up this class correctly I originally added a PHPDoc @property comment above a core class as described by others (either above the CI_Controller class or separate CI_phpStrom.php file) like this:
*
* @property Custom $custom
*
However, this didn't remove the issue, as the variable name becomes case sensitive in this case and I had to write:
*
* @property Custom $Custom
*
for my above controller code to pick up the class correctly. An alternative would be to use lowercase when calling functions (this works even if your model declaration used uppercase)
$this->load->model('custom')
$table = $this->custom->get();
The funny thing all this uppercase or lowercase didn't matter if I call my model class "Custom_model" - then it made no change if set the PHPDoc property variable to $Custom_model or $custom_model ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With