Ramin
Ramin

Reputation: 13

How can i prevent from creating multiple instances in Codeigniter?

I am new on Codeigniter and i have a question. In controller classes i need to use session, request and validation objects in every method So for each method i have to create an instance of them like below:

$session=\Config\Services::session();
$validation=\Config\Services::validation();
$request=\Config\Services::request();

How can i make one instance for whole the controller methods? I tried to creat property but it seems that i can not use an object as a property I would be thankful if you help me with that

Upvotes: 1

Views: 88

Answers (1)

steve
steve

Reputation: 2519

Make them globals - some suggestions of different approaches for how to achieve this in this thread

Upvotes: 1

Related Questions