diff options
author | Greg Aker <greg.aker@ellislab.com> | 2011-04-27 08:47:47 +0200 |
---|---|---|
committer | Greg Aker <greg.aker@ellislab.com> | 2011-04-27 08:47:47 +0200 |
commit | a6507905578f1cf209776ae3d53099a005a06823 (patch) | |
tree | 9f23bb557f920034cf65c86059c84e37efd34d79 /user_guide/general/views.html | |
parent | 60ef4ea72e169e174ff8dbb421609a178a3c0c48 (diff) | |
parent | 25d495b4a2598f771a858108a2cd2e96f0130412 (diff) |
merging in changes
Diffstat (limited to 'user_guide/general/views.html')
-rw-r--r-- | user_guide/general/views.html | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/user_guide/general/views.html b/user_guide/general/views.html index ad93f4bc7..ece746592 100644 --- a/user_guide/general/views.html +++ b/user_guide/general/views.html @@ -61,7 +61,7 @@ Views In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.</p> -<p>Views are never called directly, they must be loaded by a <a href="controllers.html">controller</a>. Remember that in an MVC framework, the Controller acts as the +<p>Views are never called directly, they must be loaded by a <a href="controllers.html">controller</a>. Remember that in an MVC framework, the Controller acts as the traffic cop, so it is responsible for fetching a particular view. If you have not read the <a href="controllers.html">Controllers</a> page you should do so before continuing.</p> @@ -90,7 +90,7 @@ you should do so before continuing.</p> <code>$this->load->view('<var>name</var>');</code> -<p>Where <var>name</var> is the name of your view file. Note: The .php file extension does not need to be specified unless you use something other than <kbd>.php</kbd>.</p> +<p>Where <var>name</var> is the name of your view file. Note: The .php file extension does not need to be specified unless you use something other than <kbd>.php</kbd>.</p> <p>Now, open the controller file you made earlier called <dfn>blog.php</dfn>, and replace the echo statement with the view loading function:</p> @@ -109,19 +109,19 @@ class Blog extends CI_Controller { </textarea> -<p>If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:</p> +<p>If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:</p> <code>example.com/index.php/<var>blog</var>/</code> <h2>Loading multiple views</h2> -<p>CodeIgniter will intelligently handle multiple calls to $this->load->view from within a controller. If more than one call happens they will be appended together. For example, you may wish to have a header view, a menu view, a content view, and a footer view. That might look something like this:</p> +<p>CodeIgniter will intelligently handle multiple calls to $this->load->view from within a controller. If more than one call happens they will be appended together. For example, you may wish to have a header view, a menu view, a content view, and a footer view. That might look something like this:</p> <p><code><?php<br /> <br /> class Page extends CI_Controller {<br /><br /> function index()<br /> {<br /> - $data['page_title'] = 'Your title';<br /> + $data['page_title'] = 'Your title';<br /> $this->load->view('header');<br /> $this->load->view('menu');<br /> $this->load->view('content', $data);<br /> @@ -132,8 +132,8 @@ class Page extends CI_Controller {<br /><br /> ?></code></p> <p>In the example above, we are using "dynamically added data", which you will see below.</p> <h2>Storing Views within Sub-folders</h2> -<p>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. Example:</p> +<p>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. Example:</p> <code>$this->load->view('<kbd>folder_name</kbd>/<var>file_name</var>');</code> @@ -159,7 +159,7 @@ $this->load->view('blogview', <var>$data</var>);</code> <p>Note: If you use an object, the class variables will be turned into array elements.</p> -<p>Let's try it with your controller file. Open it add this code:</p> +<p>Let's try it with your controller file. Open it add this code:</p> <textarea class="textarea" style="width:100%" cols="50" rows="14"> <?php @@ -195,8 +195,8 @@ class Blog extends CI_Controller { <h2>Creating Loops</h2> -<p>The data array you pass to your view files is not limited to simple variables. You can -pass multi dimensional arrays, which can be looped to generate multiple rows. For example, if you +<p>The data array you pass to your view files is not limited to simple variables. You can +pass multi dimensional arrays, which can be looped to generate multiple rows. For example, if you pull data from your database it will typically be in the form of a multi-dimensional array.</p> <p>Here's a simple example. Add this to your controller:</p> @@ -243,15 +243,15 @@ class Blog extends CI_Controller { </body> </html> </textarea> -<p><strong>Note:</strong> You'll notice that in the example above we are using PHP's alternative syntax. If you +<p><strong>Note:</strong> You'll notice that in the example above we are using PHP's alternative syntax. If you are not familiar with it you can read about it <a href="alternative_php.html">here</a>.</p> <h2>Returning views as data</h2> <p>There is a third <strong>optional</strong> parameter lets you change the behavior of the function so that it returns data as a string -rather than sending it to your browser. This can be useful if you want to process the data in some way. If you -set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it -to your browser. Remember to assign it to a variable if you want the data returned:</p> +rather than sending it to your browser. This can be useful if you want to process the data in some way. If you +set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it +to your browser. Remember to assign it to a variable if you want the data returned:</p> <code>$string = $this->load->view('<var>myfile</var>', '', <kbd>true</kbd>);</code> |