Welcome Guest, Not a member yet? Register   Sign In
"$this->request->getVar" in a model with CI4
#4

(01-24-2021, 09:06 AM)divebase Wrote: Where does the first part placed in?
PHP Code:
$model = new SomeModel();
$model->someMethod($this->request); 
I suppose in the controller or not.

In the controller, or in the service, or somewhere else where you need to work with the model

(01-24-2021, 09:06 AM)divebase Wrote: The part:
PHP Code:
$model = new SomeModel($this->request); 
gives me an Error.
'Argument 1 passed to CodeIgniter\Model::__construct() must be an instance of CodeIgniter\Database\ConnectionInterface or null, object given'

Of course you will get an error.
You need to override the constructor and call the parent's constructor.

(01-24-2021, 09:06 AM)divebase Wrote: Also placed in Controller. Ok?

In the controller, or in the service, or somewhere else where you need to work with the model

(01-24-2021, 09:06 AM)divebase Wrote: $request = App\Config\Service::request();
Where have this placed in?

In the controller, or in the service, or somewhere else where you need to work with the model. 

This is just an example of getting an instance of the IncomingRequest class.
In the controller, the $this->request property contains the same instance of the class.

Please learn PHP OOP, MVC patterns and Singleton.
This will help you understand how the framework works.
Reply


Messages In This Thread
RE: "$this->request->getVar" in a model - by iRedds - 01-24-2021, 02:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB