Tuesday, July 31, 2012

Codeigniter php frameworks: views part 2

Codeigniter php frameworks, in the previous part of Views, we talk about what is Views, and how to creating a view. Now I’m going to teach you about loading a view. To load a particular view file you will use the following function, like this “ $this->load->view('name'); ”. Where name is the name of your view file. Note: The .php file extension does not need to be specified unless you use something other than .php. Now, open the controller file you made earlier called blog.php, and replace the echo statement with the view loading function:



If you visit your site using the using you did earlier you should see your new view. The URL was similar to this, example.com/index.php/blog/. Codeigniter php frameworks was finished talk about loading a view. Now let’s talk about loading multiple views, codeigniter will intelligently handle multiple calls to $this->load->view from within a controller. If more than call happens they will be appended together. For example, you may wish have a header view, a menu view, a content view, and a footer view. That might look something like this:



Okay I think enough for this part 2 of Views. In this part we learn about loading a view and loading multiple view. We will see you in the next part of Views in Codeigniter php frameworks.

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

Sunday, July 29, 2012

Codeigniter php frameworks: views part 1


Codeigniter php frameworks, in the previous post is talking about Reserved Names. And now we will teach you about Views. What is “Views”? in codeigniter view is a simply webpage, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views if you need this type of hierarcy.

Views are never called directly, they must be loaded by a controller. Remember that in an MVC framework, the controller acts as the traffic cop, so it is responsible for fetching a particular view. Codeigniter php frameworks, If you have not read the controllers page you should do before continuing. Using the example controller you created in the controller page.

Now, let’s try to creating a view. Using your text editor, create a file called blogview.php, and save the file in your application/views/ folder. And put this code into it. Okay, I think enough for views part 1, see you in the part 2 of views, please stay at Codeigniter php frameworks.

<html>
<head>
<title>My Blog</title>
</head>
<body>
                <h1>Welcome to my Blog!</h1>
               <p>this is example page of creating a view</p>
</body>
</html>

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

Sunday, July 22, 2012

Codeigniter php frameworks: reserved names


Codeigniter php frameworks in the previous post were talk about controllers until 7 parts. Now I will give your information about Reserved Names in codeigniter. What is “reserved names”? In the order to help out, codeigniter uses a series of function and names in its operation. Because of this, some names cannot be used by a developer. Following is a list of reserved names that cannot be used.

The first is Controllers names. Since your controller classes will extends the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise your local functions will override them. Codeigniter php frameworks have list of reserved names. Do not name your controller any of these:

·         Controller
·         CI_Base
·         _ci_initialize
·         Default
·         Index

At the Functions, this is from Codeigniter php frameworks.

·         Is_really_writable()
·         load_class()
·         get_config()
·         config_item()
·         show_error()
·         show_404()
·         log_message()
·         _exception_handler()
·         Get_instance()

At the Variables, this is from Codeigniter php frameworks.

·         $config
·         $mimes
·         $lang

At the Constants, this is from Codeigniter php frameworks.

·         ENVIRONTMENT
·         EXT
·         FCPATH
·         SELF
·         BASEPATH
·         APPPATH
·         CI_VERSION
·         FILE_RAD_MODE
·         FILE_WRITE_MOD
·         DIR_READ_MODE
·         DIR_WRITE_MOD
·         FOPEN_READ
·         FOPEN_READ_WRITE
·         FOPEN_WRITE_CREATE_DESTRUCTIVE
·         FOPEN_READ_WRITE_CREATE_DESTRUCTIVE
·         FOPEN_WRITE_CREATE
·         FOPEN_READ_WRITE_CREATE
·         FOPEN_WRITE_CREATE_STRICT
·         FOPEN_READ_WRITE_CREATE_STRICT

This post of Codeigniter php frameworks: reserved names is references from http://codeigniter.com/user_guide/general/reserved_names.html.

Tuesday, July 17, 2012

Codeigniter php frameworks: controllers part 7


Codeigniter php frameworks, we will continue the next part or the last part of controllers, now is part number 7, didn’t read the part 6, please read these part first. In the part 7 we will learn about class constructors, if you intend to use a constructor in any of your controllers, you must place the following line of code like this parent::__construct(); .The reason this line is necessary is because your local constructor will be overriding the one in the parent controller class so we need to manually call it.

<?php
class Blog extends CI_Controller {
       public function __construct() {
            parent::__construct();
            // Your own constructor code
       }
}
?>

Constructors are useful if you need to set some default values, or run a default process when your class is instantiated. Codeigniter php frameworks. Constructors can return a value, but they can do some default work.

I have something for you to inform about reserved function names. Since your controller classes will extend the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise your local functions will override them. See Reserved Names at codeigniter user guide for a full list. Ok, I think this is the end of our learning about controllers, please stay at Codeigniter php frameworks.

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

Monday, July 16, 2012

Codeigniter php frameworks: controllers part 6

Codeigniter php frameworks is back, now we going to learn controllers part 6, about private function and organizing your controllers into sub-folders. If you not have read the previous part, please read it before read this post. Okay about private function, in some cases you may want certain functions hidden from public access. To make a function private, simply add an underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this.

private function _utility()
{
  // some code
}

Trying to access it via the URL, like this example.com/index.php/blog/_utility/ will not work. Now Codeigniter php frameworks talk about organizing your controllers into sub-folders, if you are building a large application you might find it convenient to organize your controllers into sub-folders. Codeigniter permits you to do this. Simply create folders within your application/controllers directory and place your controller classes within them. For the note, when using this feature the first segment of your URI must specify the folder. For example, let’s say you have a controller located here application/controllers/products/shoes.php.

To call the above controllers your URI will look something like this example.com/index.php/products/shoes/show/123. Each of your sub-folders may contain a default controller which will be called if the URL contains only the sub-folder. Simply name your default controller as specified in your application/config/routes.php file. I think just all for this part, see you in last part of controllers at Codeigniter php frameworks.

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

Thursday, July 12, 2012

Codeigniter php frameworks: controllers part 5

Codeigniter php frameworks will be learn about processing output of controllers in the title of “Codeigniter php frameworks: controllers part 5”. I think you must follow previous part of controllers to know about codeigniter controllers. We have learn about controller in the part 1, 2, 3, and 4.  I suggest you to read these part before you read this part.

Now let’s go to the lesson of part 5. Processing output, codeigniter has an output class that takes care of sending your final rendered data to the web browser automatically. More information on this can be found in the View and Output Class in the next lesson of Codeigniter php frameworks.  In some cases, however, you might want to post-process the finalized data in some way and send it to the browser yourself. Codeigniter permits you to add a function named _output() to your controller that will receive the finalized output data.

For important information, if your controller contains a function named _output(), it will always be called by the output class instead of echoing the finalized data directly. The first parameter of the function will contain the finalized output. I think you must save that information in your memory of Codeigniter php frameworks.

Code bellow is example of processing output:

public function _output($output)
{
    echo $output;
}

And note this again, that your _output() function will receive the data in finalized state. Benchmark and memory usage data will be rendered, cache file written (if your caching enabled), and header will be sent (if you use that feature) before it is handed off to the _output() function.

To have your controller’s output cached properly, its _output() method can use this code:

if ($this->output->cache_expiration > 0)
{
    $this->output->_write_cache($output);
}

If you are using this feature the page execution timer and memory usage stats might not be perfectly accurate since they will not take into acccount any further processing you do. For an alternate way to control output before any of the final processing is done, please see the available methods in the Output Class in the codeigniter user guide.

I think this enough, we will see you in the part 6 of controllers, stay up to date on Codeigniter php frameworks.

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

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/.


Tuesday, July 3, 2012

Codeigniter php frameworks: installation codeigniter part 1

Codeigniter php frameworks is back. I think, I must show you how to install codeigniter in your server, Or you can see at user guide codeigniter. First, download the latest version codeigniter from codeigniter.com, the same steps as I told in previous post . After that unzip the package, and upload the codeigniter folders and files to your server. Normaly the index.php file will be at your root. After that open the application/config/config.php file with your own text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key. Keep in mind that the steps described by Codigniter php frameworks is references from http://codeigniter.com/user_guide/.

In the first paragraph you know how to install it, in the second paragraph Codeigniter php frameworks will be show you how to set the base url to automatically, you just have to change this variable $config[‘base_url’] at config.php file into this text bellow:

$config['base_url'] =  ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ?  "https" : "http");  $config['base_url'] .=  "://".$_SERVER['HTTP_HOST'];  $config['base_url'] .=  str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

These code will generating base url to automatically, I think this code is very useful to you. So you must try it. How can I tell you these code is useful? Because, if you use the standard code of codeigniter, you should always change the “base url” configuration every time you move your codeigniter application. I think enough for today, see you in the next post of Codeigniter php frameworks.

Monday, July 2, 2012

first step to learn Codeigniter with Codeigniter php frameworks

Codeigniter php frameworks is a blog created for discusses and learns about Codeigniter. What is Codeigniter? Codeigniter a powerful PHP framework with a very small footprint, build for php coders who need a simple and elegant toolkit to create full featured web applications. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.


In this blog, I try to help you understanding about Codeigniter. To follow learning sections in this blog, first you must have a Codeigniter latest package. To find it you do not need to go anywhere, because Codeigniter php frameworks have provided a link to download a latest version of Codeigniter here. These link will be direct you to go to official website of Codeigniter for the latest version available. And after download it, please extract all object to your server.

And now you have already to learn about Codeigniter. I will help you more in the next post of this blog. We will learn together in Codeigniter php frameworks.

To remember, Codeigniter php frameworks will only learn about Codeigniter integrated with mysql databases for near future.