Skip to content
This repository
Browse code

NEW Updated tutorial 4

  • Loading branch information...
commit 11c71e1a5a3c587be8e6fc9a6dbedbefb55d6f96 1 parent 2d80ea5
Naomi Guyer authored July 20, 2012 chillu committed August 07, 2012
34  docs/en/tutorials/4-site-search.md
Source Rendered
@@ -2,13 +2,13 @@
2 2
 
3 3
 ## Overview
4 4
 
5  
-This is a short tutorial demonstrating how to add search functionality to a SilverStripe site. It is recommended that you have completed the earlier tutorials, especially the tutorial on forms, before attempting this tutorial. While this tutorial will add search functionality to the site built in the previous tutorials, it should be straight  forward to follow this tutorial on any site of your own. 
  5
+This is a short tutorial demonstrating how to add search functionality to a SilverStripe site. It is recommended that you have completed the earlier tutorials  ([Building a basic site](1-building-a-basic-site), [Extending a basic site](2-extending-a-basic-site), [Forms](3-forms)), especially the tutorial on forms, before attempting this tutorial. While this tutorial will add search functionality to the site built in the previous tutorials, it should be straight  forward to follow this tutorial on any site of your own. 
6 6
 
7 7
 ## What are we working towards?
8 8
 
9 9
 We are going to add a search box on the top of the page. When a user types something in the box, they are taken to a results page.
10 10
 
11  
-![](_images/tutorial4_search.png)
  11
+![](_images/tutorial4_search.jpg)
12 12
 
13 13
 ## Creating the search form
14 14
 
@@ -18,20 +18,18 @@ This will enable fulltext search on page content as well as names of all files i
18 18
 	:::php
19 19
 	FulltextSearchable::enable();
20 20
 
21  
-After including that in your `_config.php` you will need to rebuild the database by visiting `http://yoursite.com/dev/build` in your web browser. This will add the fulltext search columns.
  21
+After including that in your `_config.php` you will need to rebuild the database by visiting [http://localhost/your_site_name/home?flush=all](http://localhost/your_site_name/home?flush=all) in your web browser (replace localhost/your_site_name with a domain if applicable). This will add fulltext search columns.
22 22
 
23  
-The actual search form code is already provided in FulltextSearchable so when you add the enable line above to your
24  
-`_config.php` you can add your form as `$SearchForm`.
  23
+The actual search form code is already provided in FulltextSearchable so when you add the enable line above to your `_config.php` you can add your form as `$SearchForm`.
25 24
 
26 25
 In the simple theme, the SearchForm is already added to the header. We will go through the code and explain it.
27 26
 
28 27
 
29 28
 ## Adding the search form
30 29
 
31  
-To add the search form, we can add `$SearchForm` anywhere in our templates. In the simple theme, this is in
32  
-*themes/simple/templates/Includes/Header.ss*
  30
+To add the search form, we can add `$SearchForm` anywhere in our templates. In the simple theme, this is in *themes/simple/templates/Includes/Header.ss*
33 31
 
34  
-*themes/simple/templates/Includes/Header.ss*
  32
+**themes/simple/templates/Includes/Header.ss**
35 33
 
36 34
 	:::ss
37 35
 	...
@@ -39,21 +37,20 @@ To add the search form, we can add `$SearchForm` anywhere in our templates. In t
39 37
 		<span class="search-dropdown-icon">L</span>
40 38
 		<div class="search-bar">
41 39
 			$SearchForm
42  
-			<span class="search-bubble-arrow">}</span>
43 40
 		</div>      
44 41
 	<% end_if %>
45 42
 	<% include Navigation %>
46 43
 
47  
-This results in:
  44
+This displays as:
48 45
 
49  
-![](_images/tutorial4_searchbox.png)
  46
+![](_images/tutorial4_searchbox.jpg)
50 47
 
51 48
 ## Showing the results
52 49
 
53 50
 The results function is already included in the `ContentControllerSearchExtension` which
54 51
 is applied via `FulltextSearchable::enable()`
55 52
 
56  
-*cms/code/search/ContentControllerSearchExtension.php*
  53
+**cms/code/search/ContentControllerSearchExtension.php**
57 54
 
58 55
 	:::php
59 56
 	class ContentControllerSearchExtension extends Extension {
@@ -70,11 +67,9 @@ is applied via `FulltextSearchable::enable()`
70 67
 	}
71 68
 
72 69
 
73  
-The code populates an array with the data we wish to pass to the template - the search results, query and title of the
74  
-page. The final line is a little more complicated.
  70
+The code populates an array with the data we wish to pass to the template - the search results, query and title of the page. The final line is a little more complicated.
75 71
 
76  
-When we call a function by its url (eg http://localhost/home/results), SilverStripe will look for a template with the
77  
-name `PageType_function.ss`. As we are implementing the *results* function on the *Page* page type, we create our
  72
+When we call a function by its url (eg http://localhost/home/results), SilverStripe will look for a template with the name `PageType_function.ss`. As we are implementing the *results* function on the *Page* page type, we create our
78 73
 results page template as *Page_results.ss*. Unfortunately this doesn't work when we are using page types that are
79 74
 children of the *Page* page type. For example, if someone used the search on the homepage, it would be rendered with
80 75
 *Homepage.ss* rather than *Page_results.ss*. SilverStripe always looks for the template from the most specific page type
@@ -151,14 +146,13 @@ class.
151 146
 	    <% end_if %>
152 147
 	</div>
153 148
 
154  
-Then finally add ?flush=1 to the URL and you should see the new template.
  149
+Then finally add ?flush=all to the URL and you should see the new template.
155 150
 
156 151
 
157  
-![](_images/tutorial4_search.png)
  152
+![](_images/tutorial4_search.jpg)
158 153
 
159 154
 ## Summary
160 155
 
161  
-This tutorial has demonstrated how easy it is to have full text searching on your site. To add search to a SilverStripe
162  
-site, only a search form and a results page need to be created.
  156
+This tutorial has demonstrated how easy it is to have full text searching on your site. To add search to a SilverStripe site add a search form, a results page, and you're done!
163 157
 
164 158
 [Next Tutorial >>](5-dataobject-relationship-management)
BIN  docs/en/tutorials/_images/pollform.jpg
BIN  docs/en/tutorials/_images/pollresults-small.jpg
BIN  docs/en/tutorials/_images/pollresults.jpg
BIN  docs/en/tutorials/_images/tutorial4_search.jpg
BIN  docs/en/tutorials/_images/tutorial4_search.png
BIN  docs/en/tutorials/_images/tutorial4_searchbox.jpg
BIN  docs/en/tutorials/_images/tutorial4_searchbox.png

0 notes on commit 11c71e1

Please sign in to comment.
Something went wrong with that request. Please try again.