Skip to content

Commit

Permalink
Merge pull request #8521 from kenjis/docs-view-and-view-renderer
Browse files Browse the repository at this point in the history
docs: improve view() and view renderer
  • Loading branch information
kenjis authored Feb 10, 2024
2 parents 924407f + 0cec717 commit fab5398
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion user_guide_src/source/general/common_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ Service Accessors

.. literalinclude:: common_functions/004.php

For more details, see the :doc:`Views </outgoing/views>` page.
For more details, see the :doc:`Views <../outgoing/views>` and
:doc:`../outgoing/view_renderer` page.

.. php:function:: view_cell($library[, $params = null[, $ttl = 0[, $cacheName = null]]])
Expand Down
17 changes: 12 additions & 5 deletions user_guide_src/source/outgoing/view_renderer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,18 @@ View Renderer Options

Several options can be passed to the ``render()`` or ``renderString()`` methods:

- ``cache`` - the time in seconds, to save a view's results; ignored for renderString()
- ``cache_name`` - the ID used to save/retrieve a cached view result; defaults to the viewpath; ignored for ``renderString()``
- ``saveData`` - true if the view data parameters should be retained for subsequent calls

.. note:: ``saveData()`` as defined by the interface must be a boolean, but implementing
- ``$options``

- ``cache`` - the time in seconds, to save a view's results; ignored for
``renderString()``.
- ``cache_name`` - the ID used to save/retrieve a cached view result; defaults
to the ``$viewPath``; ignored for ``renderString()``.
- ``debug`` - can be set to false to disable the addition of debug code for
:ref:`Debug Toolbar <the-debug-toolbar>`.
- ``$saveData`` - true if the view data parameters should be retained for
subsequent calls.

.. note:: ``$saveData`` as defined by the interface must be a boolean, but implementing
classes (like ``View`` below) may extend this to include ``null`` values.

***************
Expand Down
22 changes: 14 additions & 8 deletions user_guide_src/source/outgoing/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Then save the file in your **app/Views** directory.
Displaying a View
=================

To load and display a particular view file you will use the following code in your controller:
To load and display a particular view file you will use the :php:func:`view()`
function like following code in your controller:

.. literalinclude:: views/001.php
:lines: 2-
Expand All @@ -64,8 +65,10 @@ If you visit your site, you should see your new view. The URL was similar to thi
Loading Multiple Views
======================

CodeIgniter will intelligently handle multiple calls to ``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
CodeIgniter will intelligently handle multiple calls to :php:func:`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:

.. literalinclude:: views/003.php
Expand Down Expand Up @@ -101,8 +104,8 @@ example, you could load the **blog_view.php** file from **example/blog/Views** b
Caching Views
=============

You can cache a view with the ``view()`` function by passing a ``cache`` option with the number of seconds to cache
the view for, in the third parameter:
You can cache a view with the :php:func:`view()` function by passing a ``cache``
option with the number of seconds to cache the view for, in the third parameter:

.. literalinclude:: views/006.php
:lines: 2-
Expand All @@ -116,7 +119,9 @@ along ``cache_name`` and the cache ID you wish to use:
Adding Dynamic Data to the View
===============================

Data is passed from the controller to the view by way of an array in the second parameter of the ``view()`` function.
Data is passed from the controller to the view by way of an array in the second
parameter of the :php:func:`view()` function.

Here's an example:

.. literalinclude:: views/008.php
Expand All @@ -142,8 +147,9 @@ Then load the page at the URL you've been using and you should see the variables
The saveData Option
-------------------

The data passed in is retained for subsequent calls to ``view()``. If you call the function multiple times
in a single request, you will not have to pass the desired data to each ``view()``.
The data passed in is retained for subsequent calls to :php:func:`view()`. If you
call the function multiple times in a single request, you will not have to pass
the desired data to each ``view()``.

But this might not keep any data from "bleeding" into
other views, potentially causing issues. If you would prefer to clean the data after one call, you can pass the ``saveData`` option
Expand Down

0 comments on commit fab5398

Please sign in to comment.