Welcome Guest, Not a member yet? Register   Sign In
Using Preloaded Model Via BaseController in Other Controllers
#4

(10-10-2021, 11:43 PM)Mr Lister Wrote: I am now at the point where I receive Attempt to read property "uri" on null on the following line:

Code:
$this->_uri_obj = $this->_request->uri;

The only way around this is by replacing:

Code:
$this->_request = $request;
with the following and removing the passed in $request variable:
Code:
$this->_request = \Config\Services::request();

You have this error because you never pass the request object to your model, $request is null:
PHP Code:
$base_markup $this->_base_layout_markup(); // nothing is passed for the $request parameter 

A model is tied to a database table. Yours seemed to be tied to a specific controller, which is weird in my opinion.
I’m not sure either why your model need to access the request object. If you follow the MVC pattern, this would be a job for the controller. The models are used for database operation, not dealing with the request and user input.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply


Messages In This Thread
RE: Using Preloaded Model Via BaseController in Other Controllers - by includebeer - 10-11-2021, 08:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB