Welcome Guest, Not a member yet? Register   Sign In
Super-object
#1

[eluser]mihailt[/eluser]
Hi guys!

Code igniter works by creating one big object and all other objects are part of that one.
What are benefits of that, comparing to having many objects seperatly?

Another question but it's kinda related to first one is why there's no possibility to create many instances of objects i mean when you use CI_Loader let's say to load some library it's automaticly creates an instance and puts it into super object, and you cannot create another instance of same library.

Any thoughts?
thanks
#2

[eluser]Tom Glover[/eluser]
In relation to your second question:

Remember you can run multiple applications in one instance of CI.
#3

[eluser]mihailt[/eluser]
[quote author="WackyWebs.net" date="1201390930"]In relation to your second question:

Remember you can run multiple applications in one instance of CI.[/quote]

not sure i understood you correctly but i think you are reffering to
user guide - managing apps

what i meant was that if you would do like

Code:
$this->load->library('session');

it's automaticly creates one object of session class inside our controller, so bassicaly it doesn't let me to create more objects of that class.


now guys understand me correctly i think Codeigniter is a great framework and so far i'm pretty happy with it, but since i kinda use it a lot i would like to know more why things are implemented in one way not another.
#4

[eluser]Pascal Kriete[/eluser]
I don't see why you would need multiple session instances. Why create two when one does everything it should.
#5

[eluser]mihailt[/eluser]
[quote author="inparo" date="1201398833"]I don't see why you would need multiple session instances. Why create two when one does everything it should.[/quote]

that not the issue i realize that in most cases this approach works, just like you said one instance of session does things right, but why every instance of a class should be singleton? Why i'm not able to manage instances on my own? And same for the first question - why do we need one big "super-object" how is that better than many objects ?

i do not complain that i lack functionality in Codeigniter. i just want to understand how codeigniter
way of doing things is better? Obviously that in the development team folks didn't just suddenly came up with that.
#6

[eluser]wiredesignz[/eluser]
You can have multiple instances of objects where practical, I often use this in my own libraries:
Code:
$_session = new CI_Session();    // new session object (not new session)

$user_mdl = new User_model();    //user defined model
And only use & get_instance(); to access existing data in the CI super-object
#7

[eluser]mihailt[/eluser]
[quote author="wiredesignz" date="1201408357"]You can have multiple instances of objects where practical, I often use this in my own libraries:
Code:
$_session = new CI_Session();    // new session object (not new session)

$user_mdl = new User_model();    //user defined model
And only use & get_instance(); to access existing data in the CI super-object[/quote]

hey that's pretty nice thanks Smile

so now it's only one question left.
#8

[eluser]thurting[/eluser]
[quote author="mihailt" date="1201385692"]Hi guys!

Code igniter works by creating one big object and all other objects are part of that one.
What are benefits of that, comparing to having many objects seperatly?

[/quote]

This set up allows for easy access to objects from anywhere in the application using the global get_instance function. It is kind of a jacked up singleton and version of the front controller pattern. I think the design could be better, but it works.
#9

[eluser]mihailt[/eluser]
[quote author="thurting" date="1201415068"]It is kind of a jacked up singleton and version of the front controller pattern. I think the design could be better, but it works.[/quote]

Yeah, that exact my thinking, it works so it's pretty much usable.
I'm just trying to justify the design solution.
#10

[eluser]zilverdistel[/eluser]
[quote author="wiredesignz" date="1201408357"]You can have multiple instances of objects where practical, I often use this in my own libraries:
Code:
$_session = new CI_Session();    // new session object (not new session)

$user_mdl = new User_model();    //user defined model
And only use & get_instance(); to access existing data in the CI super-object[/quote]

when you use this, is it still required to 'load' your model before?




Theme © iAndrew 2016 - Forum software by © MyBB