Closed lipsaraiva closed 3 years ago
I have the same problem...
If you look at the src for 4.0.1 $request
is typed as HTTP\IncomingRequest
which is the concrete class that declares a getVar
function. Then in 4.1 it has become RequestInterface
which does not declare getVar
.
You may be able to override it by creating a non-executable ide helper file in your project root that types $request
as the concrete type.
namespace CodeIgniter;
/**
* Class Controller
*/
class Controller
{
/**
* Instance of the main Request object.
*
* @var HTTP\IncomingRequest
*/
protected $request;
}
I got same problem
Closing this as it is working as designed. Workaround provided above. Looks like ci uses @mixin
on the request interface which when implemented will resolve this #123
If you look at the src for 4.0.1
$request
is typed asHTTP\IncomingRequest
which is the concrete class that declares agetVar
function. Then in 4.1 it has becomeRequestInterface
which does not declaregetVar
.You may be able to override it by creating a non-executable ide helper file in your project root that types
$request
as the concrete type.namespace CodeIgniter; /** * Class Controller */ class Controller { /** * Instance of the main Request object. * * @var HTTP\IncomingRequest */ protected $request; }
Work fine, thanks! ❤
I'm outside of the controller and made my own library and tried with this recommendation from the docs.
When I tried $someClass->getVar()
, it said the method is undefined.
But I still got the issue, how do I fix it? Thanks.
i found this from the documentation: https://codeigniter.com/user_guide/concepts/http.html#working-with-requests-and-responses
i impemented like this and work!
class SomeClass extends BaseController{
protected $mRequest;
public function __construct()
{
$this->mRequest = service("request");
}
public function someFunction(){
$this->mRequest->getVar();
}
}
after public function store(){
you can put this code
$request = \Config\Services::request();
and change
$this->request->getVar()
to be
$request->getVar()
thank you
thank to you all
Just extends from BaseController not through Controller
codeigniter 4 just extends from BaseController not Controller and by default will have that attribute
<?php
namespace App\Controllers;
use App\Models\Libro;
class Libros extends BaseController{
public function guardar(){
$name= $this->request->getVar("name");
}
}
?>
its same problem but differend method i got error like this...
`?php
namespace App\Controllers;
use CodeIgniter\Controller; use App\models\M_Siswa;
class Siswa extends controller { public function __construct() { $this->model = new M_Siswa; }
public function index()
{
$data = [
'judul' => 'Data Siswa',
'siswa' => $this->model->getAllData()
];
echo view('templates/v_header', $data);
echo view('templates/v_sidebar');
echo view('templates/v_topbar');
echo view('siswa/index.php', $data);
echo view('templates/v_footer');
}
public function tambah()
{
$data = [
'nisn' => $this->request->getPost('nisn'),
'nama' => $this->request->getPost('nama')
];
$success = $this->model->tambah($data);
if ($success) {
return redirect()->to(base_url('siswa'));
}
}
}
?>`
getPost cannot read kindly how fixed this?
Only one Thing is to do -> Change the YourController extends controller to YourCountroller extends BaseController
Iam sorry sir!! Can you give me a example?
Jum, 24 Des 2021 pukul 13.09 Rajatsingh007 @.***> menulis:
[image: Capture] https://user-images.githubusercontent.com/87520507/147323174-01b6f19b-a7b8-4f3a-9a29-0de07586edc0.PNG
Only one Thing is to do -> Change the YourController extends controller to YourCountroller extends BaseController
— Reply to this email directly, view it on GitHub https://github.com/bmewburn/vscode-intelephense/issues/1670#issuecomment-1000673608, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQ26JQ3FD2FKMV7J2HIEB3USQFCFANCNFSM4XO74PBA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you commented.Message ID: @.***>
i found this from the documentation: https://codeigniter.com/user_guide/concepts/http.html#working-with-requests-and-responses
i impemented like this and work!
class SomeClass extends BaseController{ protected $mRequest; public function __construct() { $this->mRequest = service("request"); } public function someFunction(){ $this->mRequest->getVar(); } }
thank you very much bro... solved
Just gived protected $mRequest; ???
Rab, 26 Jan 2022 pukul 08.15 Hazzanawarafik @.***> menulis:
i found this from the documentation: https://codeigniter.com/user_guide/concepts/http.html#working-with-requests-and-responses
i impemented like this and work!
class SomeClass extends BaseController{
protected $mRequest; public function __construct() { $this->mRequest = service("request"); } public function someFunction(){ $this->mRequest->getVar(); }
}
thank you very much bro... solved
— Reply to this email directly, view it on GitHub https://github.com/bmewburn/vscode-intelephense/issues/1670#issuecomment-1021762446, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQ26JVSCHBZCHTG3VE5WVLUX5DL3ANCNFSM4XO74PBA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you commented.Message ID: @.***>
Followed @Rajatsingh007 's solution.. worked like magic!!
`<?php
namespace App\Controllers;
use CodeIgniter\Controller; use App\Models\UserModel; use App\Controllers\BaseController; //use BaseController
class Login extends BaseController //use BaseController instead of Controller`
When used the methods 'getPost', 'getGet' or 'getVar' from CodeIgniter 4 framework in VSC, an alert appears to me: "Undefined method 'getVar'.intelephense(1013)".
To Reproduce
$data = array( 'id' => $this->request->getVar('id'), 'nome' => $this->request->getVar('nome'), 'apelido' => $this->request->getVar('apelido') );
Expected behavior The code is OK, The alert should not appear.
Screenshots
Platform and version Windows 10, CodeIgniter 4 and Intelephense 1.6.3.