Monday, July 9, 2012

Codeigniter php frameworks: controllers part 2

Codeigniter php frameworks will be continues the part to of controllers, if you have not read the part 1 of controllers. Please read it before you read this. Now we were learn about functions. In the part 1, we give you the example of simple code right? Now you look these code, and you will se the function name is index(). The “index” function is always loaded by default if the second segment of the URI is empty. Another way to show your “Hello World” message would be like this example.com/index.php/blog/index/ .

The second segment of the URI determines which function in the controller gets called. Let’s try it. Codeigniter php frameworks would you to add new function to your controller. If you don’t have any idea to build something, you can follow this code to your controller.

<?php
class Blog extends CI_Controller {
                public function index(){
                                echo 'Hello World!';
                }
                public function comments(){
                                echo 'Look at this!';
                }
}
?>

Now load the following URL to see the comment function, example.com/index.php/blog/comments/. After that you will see your new message. I think enough for this part, we will see you in the part 3 of controllers, stay learn at Codeigniter php frameworks.

This post of Codeigniter php frameworks: controllers part 2 is references from http://codeigniter.com/user_guide/general/controllers.html.

No comments:

Post a Comment