Wednesday, July 11, 2012

Codeigniter php frameworks: controllers part 4

Codeigniter php frameworks will be go to the part 4 of controllers. If you have not read the previous part, click here. Now we learn about defining a default controller. Codeigniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable $route['default_controller'] = 'Blog';.

Where blog is the name of controller class you want to be use. If you now load your main index.php file without specifying any URI segments you’ll see your Hello World message by default. Codeigniter php frameworks is finish talking about default controller, now we going to remapping function calls. As defining a default controller, the second segment of the URI typically determines which function in the controller get called. Codeigniter permits you to override this behavior through the use of the  function like this.

public function _remap()
{
    // Some code here...
}

The override function call (typically the second segment of the URI) will be passed as a parameter to the _remap() function like list code number 1 on this paragraph bellow. Any extra segment after the method name are passed into _remap() as an optional second parameter. This array can be used in combination with PHP’s call_user_func_array to emulate Codeigniter’s default behavior. You can see the example code at list code number 2 on this paragraph bellow. Okay enough for part 4 of controller, see you at part 5 of controller only on Codeigniter php frameworks.

Code number 1

public function _remap($method)
{
    if ($method == 'some_method')
    {
        $this->$method();
    }
    else
    {
        $this->default_method();
    }
}

Code number 2

public function _remap($method, $params = array())
{
    $method = 'process_'.$method;
    if (method_exists($this, $method))
    {
        return call_user_func_array(array($this, $method), $params);
    }
    show_404();
}

For the note of remapping function calls , if your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.

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

Tuesday, July 10, 2012

Codeigniter php frameworks: controllers part 3

Codeigniter php frameworks will be go to the part 3 of controllers. You have to read the previous part to follow this post. Okay, now let’s talk about passing URI segments to your function. If your URI contains more than two segments they will be passed to your function as parameter. For the example, let’s say you have a URI like this example.com/index.php/products/shoes/sandals/123.


Your function will be passed URI segments number 3 and 4 (“sandals” and “123”). To easy learning, Codeigniter php frameworks will be show you the example of function who have the passing URI segments.


<?php

class Products extends CI_Controller {

public function shoes($sandals, $id) {

echo $sandals;

echo $id;

}

}

?>


Before closing this part of controllers, I have important things about this feature. If you are using URI Routing (will be discuss in another post) feature, the segments passed to your function will be the re-routed ones. Okay I thing enough for this part of controllers, keep updated with post of Codeigniter php frameworks.


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


For information, Codeigniter php frameworks suggest you to follow this blog, if you interested with codeigniter, because write the post is references from codeigniter user guide.

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.

Sunday, July 8, 2012

Codeigniter php frameworks: controllers part 1

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.

Saturday, July 7, 2012

Codeigniter php frameworks: codeigniter URLs part 2

Codeigniter php frameworks will be next to part two of codeigniter URLs. If you have not read the part one of codeigniter URLs, please follow this link to read it. Okay back to the lesson, now we talk about Adding a URL suffix. To active it you can find this configuration at config/config.php, you can specify that will be added to all URLs generated by codeigniter. for example, if the URL is example.com/index.php/products/view/shoes, you can optionally add a suffix, like .asp, making the page appear to be of a certain type like this example.com/index.php/products/view/shoes.asp.

And the last lesson of codeigniter URLs is Enabling Query Strings, in some cases you might prefer to use query strings URLs like this index.php?c=products&m=view&id=345. Codeigniter optionally supports this capability, which can be enabled in your application/config.php file. Codeigniter php frameworks will be show you the config file preview. The preview will be like this.

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

If you change “enable_query_strings” to TRUE this feature will become active. Your controllers and functions will then be accessible using the “trigger” words you’ve set to invoke your controllers and methods like this index.php?c=controller&m=method. I think enough for this post of codeigniter URLs, see you in the next post in Codeigniter php frameworks.

Please note this, If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.

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

Thursday, July 5, 2012

Codeigniter php frameworks: codeigniter URLs part 1

Codeigniter php frameworks will teach you about codeigniter URLs. If you not understand about installing codeigniter, please follow the previous post. The codeigniter URLs feature is designed to be search engine and human friendly. For the example is example.com/news/article/my_article. Firstly is URI Segment, the segment in the URL is following with the Model-View-Controller(MVC). And for the structure  is example.com/class/function/ID. Class is the first segment represents the controller class that should be invoke. Function is the second segment represents the class function, or method, that should be called. And ID is the third, and any additional segment, represents  the ID and any variables that will be passed to the controller.

For the second learn about codeigniter URLs is How to removing the index.php. what is index.php? index.php is the main file to default appear to your URL. The actually codeigniter URL is example.com/index.php/class/function/ID. Codeigniter php frameworks will be show you how to remove it. You can easily remove it by using .htaccess file with some simple rules. Rules bellow is example of such a file, using the negative method in which everything is redirected except the specified items

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

I think enough for the part 1 of codeigniter URLs, we will discuss another feature of codeigniter URLs in the next post of Codeigniter php frameworks.

This post of Codeigniter php frameworks: codeigniter URLs part 1 is references from http://codeigniter.com/user_guide/general/urls.html.

Wednesday, July 4, 2012

Codeigniter php frameworks: installation codeigniter part 2

Codeigniter php frameworks will show you next part of installation codeigniter. In the previous post of codeigniter php frameworks we show you how to install codeigniter from downloading the package until setting up the base url configuration. Now let’s learn about using the encryption key and another about installation the codeigniter.

If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private. Codeigniter php frameworks will show you how to use it. You must open your main index.php file and set the $system_folder and $application_folder variables at the top of the file with the new name you've chosen. For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser. By default, .htaccess files are included in each folder to help prevent direct access, but it is best to remove them from public access entirely in case the web server configuration changes or doesn't abide by the .htaccess.
After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. /www/MyUser/system. One additional measure to take in production environments is to disable PHP error reporting and any other development-only functionality. In codeIgniter, this can be done by setting the ENVIRONMENT constant, which is more fully described on the security page of codeigniter user manual. I think that’s all, see you at another post of Codeigniter php frameworks.

Some post of Codeigniter php frameworks is references from http://codeigniter.com/user_manual/.