diff --git a/user_guide_src/source/outgoing/views.rst b/user_guide_src/source/outgoing/views.rst index 19121c98b86a..533e3c9bead5 100644 --- a/user_guide_src/source/outgoing/views.rst +++ b/user_guide_src/source/outgoing/views.rst @@ -19,7 +19,7 @@ Using the example controller you created in the controller page, let’s add a v Creating a View =============== -Using your text editor, create a file called ``BlogView.php`` and put this in it:: +Using your text editor, create a file called ``blog_view.php`` and put this in it:: @@ -53,7 +53,7 @@ Now, open the controller file you made earlier called ``Blog.php``, and replace { public function index() { - echo view('BlogView'); + echo view('blog_view'); } } @@ -107,11 +107,11 @@ You can store views under a **View** directory that is namespaced, and load that PHP does not support loading non-class files from a namespace, CodeIgniter provides this feature to make it possible to package your views together in a module-like fashion for easy re-use or distribution. -If you have ``Blog`` directory that has a PSR-4 mapping set up in the :doc:`Autoloader ` living +If you have ``example/blog`` directory that has a PSR-4 mapping set up in the :doc:`Autoloader ` living under the namespace ``Example\Blog``, you could retrieve view files as if they were namespaced also. Following this -example, you could load the **BlogView** file from **/blog/views** by prepending the namespace to the view name:: +example, you could load the **blog_view.php** file from **example/blog/Views** by prepending the namespace to the view name:: - echo view('Example\Blog\Views\BlogView'); + echo view('Example\Blog\Views\blog_view'); Caching Views ============= @@ -140,7 +140,7 @@ Here's an example:: 'message' => 'My Message', ]; - echo view('blogview', $data); + echo view('blog_view', $data); Let's try it with your controller file. Open it and add this code:: @@ -155,7 +155,7 @@ Let's try it with your controller file. Open it and add this code:: $data['title'] = "My Real Title"; $data['heading'] = "My Real Heading"; - echo view('blogview', $data); + echo view('blog_view', $data); } } @@ -184,7 +184,7 @@ into the `$option` array in the third parameter. 'message' => 'My Message', ]; - echo view('blogview', $data, ['saveData' => true]); + echo view('blog_view', $data, ['saveData' => true]); Additionally, if you would like the default functionality of the view function to be that it does save the data between calls, you can set ``$saveData`` to **true** in **app/Config/Views.php**. @@ -212,7 +212,7 @@ Here’s a simple example. Add this to your controller:: 'heading' => 'My Real Heading', ]; - echo view('blogview', $data); + echo view('blog_view', $data); } }