CodeIgniter Forums
How to use suggestions and find usage with PHPStorm - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Best Practices (https://forum.codeigniter.com/forum-12.html)
+--- Thread: How to use suggestions and find usage with PHPStorm (/thread-80441.html)



How to use suggestions and find usage with PHPStorm - sprhld - 11-01-2021

Hello!

I use PHPStorm and since my code becomes more complex, I miss the suggestions if I want to use a model, I can't see my docs if I use a method and also in the model file all methods are grey, which means, they aren't ins use, witch also means, I can't refactor if necessary. Let me show you what I have at the moment:

First of all, I use a BaseModel, where I have some db-request, which I use in several models. The crtSlug() here I can refactor and I find all usage if I search.

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;

class 
BaseModel extends Model
{

    public function crtSlug(string $name): string
    
{
        /* Fancy stuff here */
    }



Then, SubjectModel extend BaseModel mostly. Not all, some extends the CI-model like above. crtForm() is grey, I can't find usage.

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;
use 
App\Models\BaseModel;

class 
SubjectModel extends BaseModel
{

    protected $table        'subjects';
    protected $primaryKey    'id';
    protected $returnType    'object';
    protected $allowedFields = ['id''slug''type''name''description'];

    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    public function crtForm($data NULL): array
    {
        /* hold all data for my forms */
    }


What I also do is, to load my models in the BaseController. The very most stuff is need on every page, is it for the navigation or something else.

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Psr\Log\LoggerInterface;

class 
BaseController extends Controller
{
    protected $request;

    protected $ionAuth;
    protected $subject;
    protected $timeline;

    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        parent::initController($request$response$logger);

        // Loading things
        $this->ionAuth  = new \IonAuth\Libraries\IonAuth();
        $this->subject  = new \App\Models\SubjectModel();
        $this->timeline = new \App\Models\TimelineModel();

        // if logged in...
        if ($this->ionAuth->loggedIn() == '1')
        {
            /* one of the reasons to make use of the base controller :) */
        }
    }


And this are normal controllers. Here I can auto complete $this->subject but nothing more. I can't see the methods, which are in the subjectModel. Also, you see "timelineModel" above, which only extends Model. This is the basic structure and this one works well weeks ago. But nor yet anymore :/

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Model;
use 
App\Controllers\BaseController;

class 
Subject extends BaseController
{
    public function index()
    {
        $this->subject->crtSlug();
    }



So, can anyone help me to write the code better or configure PHPStorm to use the alluded features. Thank you Smile


RE: How to use suggestions and find usage with PHPStorm - kenjis - 11-01-2021

It seems strange.
I can auto complete $this->subject->

[Image: 2021-11-01-20-41-33.png]


RE: How to use suggestions and find usage with PHPStorm - sprhld - 11-01-2021

Hmm... Strange. It work here only on the BaseController. There I have the suggestions and I can find the usage when I search for it. It seems, that any kind of a link between the BaseController and the normal controllers are not working. I cleared any cache in the meantime and run code inspections, but without any effect.


RE: How to use suggestions and find usage with PHPStorm - InsiteFX - 11-02-2021

Works here also.


RE: How to use suggestions and find usage with PHPStorm - sprhld - 11-13-2021

Okay, it is not because of the structure of CI and it is more my system like the configuration or what so ever :/ If I found a solution, I will post it.

Thank you!