Wednesday, August 1, 2012

Codeigniter php frameworks: views part 3


Codeigniter php frameworks will be start to views part 3, if you haven’t read the previouspart, please read it before. In part 3, we will be teaching you about Storing Views within Sub-folders and Adding Dynamic Data to the view. Firstly is Storing Views within Sub-folders, your view files can also be stored within sub-folders if you prefer that type of organization. When doing so you will need to include the folder name loading the view, like this $this->load->view('folder_name/file_name');.

Now let’s change our learning to Adding Dynamic Data to the View. Data is passed from the controller to the view by way of an array or an object in the second parameter of the view loading function. Codeigniter php frameworks have example using an array. So you can copy it to your controller file with your text editor.

using array variables.
using object variables.

FYI, if you use an object, the class variables will be returned into array elements. We will show you the code if you have and controller, open it and use this code. Codeigniter php frameworks.


After that open your view file and change the text to variables that correspond to the array keys in your data, this is the code.


And now you can try it. Okay I think enough for this part 3 of views, we will see you in the next part. Stay at Codeigniter php frameworks. Keep shipping!!!

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

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.