1 00:00:00,410 --> 00:00:03,783 The project files for this application are all set up and 2 00:00:03,783 --> 00:00:05,881 ready to accept data from the API. 3 00:00:05,881 --> 00:00:09,860 They use Bootstrap for styling and Twig for HTML templates. 4 00:00:09,860 --> 00:00:13,300 I included these packages in the composer.json file. 5 00:00:13,300 --> 00:00:16,880 So when we ran the composer require from the previous video 6 00:00:16,880 --> 00:00:19,230 those packages were also installed. 7 00:00:19,230 --> 00:00:22,410 If you are unfamiliar with Bootstrap Twig Templates or 8 00:00:22,410 --> 00:00:25,560 Composer, please check the notes associated with this video. 9 00:00:27,200 --> 00:00:29,999 Let's preview the current state of the project in a browser. 10 00:00:34,655 --> 00:00:38,502 We have a home page that introduces people to the project, 11 00:00:38,502 --> 00:00:43,292 a Search page that isn't actually providing search capabilities yet, 12 00:00:43,292 --> 00:00:47,375 and a Project Repos page that reads the composer.LOC file and 13 00:00:47,375 --> 00:00:50,620 gives us a list of packages used in this project. 14 00:00:51,810 --> 00:00:55,840 We'll be adding two features, the search capability and 15 00:00:55,840 --> 00:00:59,100 the ability to watch or on watch packages. 16 00:01:00,240 --> 00:01:03,370 Let's go back to Workspaces and start with the search feature. 17 00:01:05,250 --> 00:01:08,522 Open search.php. 18 00:01:08,522 --> 00:01:12,531 After our Twig object, let's create a new API object. 19 00:01:21,056 --> 00:01:23,745 Next, we need to check for search string. 20 00:01:26,457 --> 00:01:31,148 If (!empty($_GET['q'])) 21 00:01:37,609 --> 00:01:43,177 If the search string is set we can use that in our API GET method. 22 00:01:43,177 --> 00:01:45,049 Let's start by creating a response. 23 00:01:48,805 --> 00:01:53,982 $api->get( and now we're going to '/search/repositories/. 24 00:02:02,567 --> 00:02:05,889 The get method accepts two optional parameters, 25 00:02:05,889 --> 00:02:10,480 additional parameters for the URL and additional headers. 26 00:02:10,480 --> 00:02:13,300 So we can add the search string as a second parameter. 27 00:02:14,340 --> 00:02:19,092 The second parameter is an array, so we add 'q'. 28 00:02:22,732 --> 00:02:29,384 And set it equal to filter_input(INPUT_GIT, 29 00:02:29,384 --> 00:02:34,936 'q', FILTER_SANITIZE_STRING). 30 00:02:40,449 --> 00:02:45,130 Next we decode the response so that we can access the repositories. 31 00:02:55,398 --> 00:02:59,801 The search template is set up to display those repositories, so 32 00:02:59,801 --> 00:03:04,540 all we need to do is pass the repositories as an argument named items. 33 00:03:05,680 --> 00:03:08,333 Let's move the arguments out of the render call and 34 00:03:08,333 --> 00:03:10,379 then we can add the items to that array. 35 00:03:23,600 --> 00:03:29,211 Now we can add $args['items'] 36 00:03:29,211 --> 00:03:34,264 = $repositories->items. 37 00:03:36,631 --> 00:03:38,764 Let's test our search page in the browser.