Codeigniter php
frameworks, in the previous post we talk about codeigniter URLs. Now, we
will learn about controllers. What is controller? Controller is simply a class
file that is named in a way that can be associated with a URI. Consider this
URI for example, example.com/index.php/blog/. In
that’s example, codeigniter would attempt to find a controller named blog.php and load it. When a controller’s
name matches the first segment of a URI, it will be loaded.
Now let’s, try to make a simple
controller so you can see it in action. Using your text editor, create a file
called blog.php. Codeigniter php frameworks has provided
the simple code for controller. Please put the following code in it to file blog.php.
<?php
class Blog extends CI_Controller {
public function index(){
echo
'Hello World!';
}
}
?>
And then save the file to your application/controllers
folder. Now visit the your site using a URL similar to this example.com/index.php/blog/. If you
did it right, you should see Hello
World!. Also, always make sure your controller extends
the parent controller class so that it can inherit all its functions. Okay,
enough for this part of controllers, wait for next part of controllers at Codeigniter
php frameworks.
This post of Codeigniter php frameworks: controllers part 1
is references from http://codeigniter.com/user_guide/general/controllers.html.
Comments
Post a Comment