views:

19

answers:

2

In what phase does the object creation happen at CodeIgniter ?

$newObj = new SomeClass(); 

In which stage this happens ?

+1  A: 

At runtime, when control reaches that statement.

Matthew Flaschen
Is there any example ? Does it mean before going to view files ?
sagarmatha
I don't know what you mean by "going to view files."
Matthew Flaschen
+1  A: 

As the previous answer said, it happens when control reaches the statement. If the statement is in a view file it would happen then but it would be unusual to be creating objects in a view. It's more likely that you'd have that in a controller. Since the controller typically loads the view as a final step, the object would be created before loading the view.

Hibiscus
can you pls give any example
sagarmatha
Sure. Let's say you've got a controller with a function show(). In show() you have various logic, including your $newObj = new SomeClass(), followed by some more logic and finally a $this->load->view('show_view'). The view is only processed then, so any statements in the controller are processed before the view is loaded. You shouldn't really be creating any objects in the view since all the heavy lifting should be done in the controller and any objects you need in the view should just be passed from the controller through your $this->load->view statement.
Hibiscus