Problem with properly setting up models/libraries for code completion in codeigniter
Hello all,
I am currently in my evaluation period for phpstorm and I really like it except that I cannot get code completion & goto functionality to work properly for my models, libraries and other controllers.
I was able to get the core codeignither completion setup using the files here: https://github.com/topdown/phpStorm-CC-Helpers/tree/master/CodeIgniter
I have tried the my_models.php example listed above but it will not work. I can Ctrl+Click the 'Auth_model' in the my_models.php file which will take me to the correct Auth_model class but in my controllers anything referencing $this->auth_model->example(); will say "Field 'auth_model' not found in class Main.
my_models.php file:
<?php die();
/**
* Add you custom models here that you are loading in your controllers
*
* <code>
* $this->site_model->get_records()
* </code>
* Where site_model is the model Class
*
* ---------------------- Models to Load ----------------------
*
* @property Auth_model $auth_model
*
*
*/
class my_models
{
}
// End my_models.php
Any ideas? This is really the only issue stopping me from switching to phpstorm.
Thanks!
请先登录再写评论。
Just wanted to update if anyone else runs into the same problem. I'm not sure if this is the correct way but it does work.
Adding your models/libraries to the CI_phpStorm.php file which has the data to autocomplete codeigniter stuff worked for me. Add them after the CI stuff before the CI_Controller class.
Example:
* @property CI_Security $security Security Class, xss, csrf, etc...
* Start custom libraries / models here
* @property auth_model $auth_model Custom Auth Model
*/
class CI_Controller{}
Yes it still works for me. I wasn't able to get the my_models working but if you add your models in the doc block before class CI_Controller() and before CI_Model() it seems to work.
Here is a sample of my modified CI_phpStorm.php:
/**
* Entries here show in controllers
* @property custom_model $custom_model
*/
class CI_Controller{}
/**
* Entries here show in models
* @property custom_model $custom_model
*/
class CI_Model{}
Thanks for following up - that really helped me nail down my problem.
Not exactly sure why, but this solved my issue.
My model classes start with uppercase letter, such as:
class Custom extents CI_Model {}
When I defined this model in PHPDoc I wrote:
* @property Custom $custom My custom model
I thought this was very much in line what a saw above, where for example the core model class was commented.as
* @property CI_Model $model
However, my custom model was not recognized. So when tried to replicate you model class "custom_model" it suddenly worked.
Now I got really curious, it could be either an uppercase issue, or the reason I didn't add "_model" - here's what I found:
@property Classname $Classname
to be picked up correctly (note the uppercase in the variable name - @property Classname $classname did not work)
I have no idea why the uppercase variable name only becomes an issue with "single" names, and why "custom_model" doesn't trigger the same problems.
But at least I've resolved it for me - thanks again for following up - maybe that helps someone else stubborn like me who doesn't want to add "_model" and wants to use capitalized class names.