Confused About Objects and Classes in CodeIgniter?

I am new to CodeIgniter and wonder. I am a little confused about classes, libraries and objects.

Does CodeIgniter replace the regular PHP method of user objects, i.e. $var = new car();, with libraries, that is $this->load->library('some_library'); $this->some_library->some_function();?

If both are valid, is there a difference? If so, what are the differences and when do I use one over the other? What is more common / correct?

I ask because I created the class, but I'm not sure if this is the correct way to create it.

Thanks in advance

+3
source share
3 answers

CI , , // .

( ) -singleton- require . , , , .

($this->load) , , (, - , , . ) $this.

. , "" , .

, , . "", CI- .

+2

CodeIgnitier. PHP. , , ...

, "" - library, , ( , ). 1 ( ).

factory. , , .

, . ..

+5

, Inversion of Control (, , CodeIgniter).

car, new car(). , $var a racecar? $var , car, . , , car - , . , , . , $var mockcar. , $var = new car().

?

0

Source: https://habr.com/ru/post/1764344/


All Articles