Welcome Guest, Not a member yet? Register   Sign In
PHPStorm yellow "Method not found in" notices
#1

(This post was last modified: 04-13-2020, 01:18 PM by Leo. Edit Reason: clarity )

Does anyone use PHPStorm? How do I fix the annoying method not found warnings\errors when using singleton instance of class across functions in controller?

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\ProductsModel;

class 
Products extends BaseController
{
    protected $model;

    public function product_filters()
    {
        $this->model = new ProductsModel();
        $this->model->setTable('filters');
        $this->data['filters'] = $this->model->findAll();
////////////find all is lit up, declaration can be found

        if(isset($_POST)) {
            if (isset($_POST['add'])) {
                $this->new_filter();
            }
            return redirect()->to(current_url('products/product_filters'));
        }

        echo view('admin'$this->data);
        return null;
    }

    private function new_filter()
    {
        $name trim_and_filter('name');
        //check for existing, if no then insert
        if(!$this->model->where('name'$name)->first()) {
//////////here i keep getting yellow error method not found - but it works fine! How to fix this?? Its so annoying.
            $this->model->save(['name' => $name]);
        }
    }


You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#2

I don't have the solution but can suggest clicking on the small "man in the hat" icon at the bottom right. There you can configure code inspection.

I do have plugin installed "CodeIgniter" by Martynas Sateika. (Press CTRL+ALT+S > Plugins).

Don't have resolution problems, and didn't have to configure them.

Also in settings you could go to "Languages & Frameowrks > PHP > CodeIgniter" and tick checkbox "Enable CodeIgniter Integration".
Reply
#3

(This post was last modified: 04-14-2020, 05:26 AM by Leo. Edit Reason: clarity )

The codeigniter plugin didn't help. I figured it out after digging the internet for a while - heres to any other newb, like me, looking.
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\MediaModel;

class 
Media extends BaseController
{
    /* @var $model MediaModel */
    protected $model;

    public function doSomething()
    {
        $this->model = new MediaModel();
        $this->model->setTable('table');
        
$stuff $this->doSomethingElse();
    }
    
    
private function doSomethingElse()
    {
        return $this->model->findAll(); //NO MORE TEARS! PHPSTORM FINDS THE METHOD
    }



So basically do this:
/* @var $model MediaModel */
protected $model;
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#4

(04-14-2020, 04:43 AM)Leo Wrote: The codeigniter plugin didn't help. I figured it out after digging the internet for a while - heres to any other newb, like me, looking.
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\MediaModel;

class 
Media extends BaseController
{
    /* @var $model MediaModel */
    protected $model;

    public function doSomething()
    {
        $this->model = new MediaModel();
        $this->model->setTable('table');
        $stuff $this->doSomethingElse();
    }
    
    
private function doSomethingElse()
    {
        return $this->model->findAll(); //NO MORE TEARS! PHPSTORM FINDS THE METHOD
    }



So basically do this:
/* @var $model MediaModel */
protected $model;

The plugin supports Codeigniter 3. For CodeIgniter 4 you can use this method:
Copy the attached file to the app folder: this should enable automatic completion in PhpStorm
The file is an experiment and is not complete.
I hope it is useful.

Attached Files
.php   phpstorm.php (Size: 68.27 KB / Downloads: 26)
Codeigniter 4 - Docker Image [github] [docker hub]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB