Welcome Guest, Not a member yet? Register   Sign In
Index function
#1

[eluser]Eugene Serkin[/eluser]
Hello!
I've got a small question about, the index function. I searched everywhere for this particular function, but didn't find it anywhere. Is it an interface of some sort and does parent controller class implement it or how is it setup?

Thank you a lot for help.
#2

[eluser]Ben Edmunds[/eluser]
NetJunky,

You set it up yourself in your controller and CI will run that by default if no specific method is called in the url.

For example:

Code:
class your_controller extends Controller
{
   function index()
   {
      echo 'this is ran by default';
   }
}

Make sense?
#3

[eluser]Eugene Serkin[/eluser]
Yes. Well actually I know that as I made some apps with CI, but what I really ment is that where could I find the code where is set that index should be the default function? Because as I understand in PHP language there is no default function in class exept the __constructor function which is activated, when you make instance of some class.

Okey. Enough of my bla bla bla. Again my question:
"Where in CI source code can I find the part where it is told that index function is the default function in controller?"

Still thnx Ben Edmunds.
#4

[eluser]cahva[/eluser]
It's set in the router: system/libraries/Router.php
#5

[eluser]Eugene Serkin[/eluser]
Ou. I thought, that it is some sort of interface which is applied to Controller class.
And only when I thought, that I got a hang of it...Sad
#6

[eluser]InsiteFX[/eluser]
To the point index.php is the the file that loads the
Routing and all other libraries, think of it as the
CodeIgniter Bootstrap loader. It also loads the
CodeIgniter Front Controlloer then your Controller.

It's the first file on a web site that starts up.

require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;

Now start tracing that file out and you will see how
CodeIgniter sets everything up.

In CodeIgniter 2.0 up coming this has been changed.
form directory CodeIgniter to core...

require_once BASEPATH.'core/CodeIgniter'.EXT;

If you look at the last line in the file you will
see what it loads and how it intilalizes everything.

It's usally called a Bootstrap loader.

Enjoy
InsiteFX
#7

[eluser]Eugene Serkin[/eluser]
Yep. First time did so. Started from index.php and up the ladder. Little bit later wanted to implement simple example of MVC. Actualy very raw written, but I'm still learning. When I got to the part in my example with index function I stuck.
At the moment it looks pretty ugly in my opinion: http://codaset.com/jeserkin/mvc-testing. Maybe later it will.
As the saying goes: "Time makes it own repairs".

Thnx to everyone.




Theme © iAndrew 2016 - Forum software by © MyBB