Skip to content

Commit 35b6f4b

Browse files
Merge #180
180: Add landing_getting_started_1 code samples r=brunoocasali a=brunoocasali Add a `landing_getting_started_1` code sample to be on the new landing page block. Closes: #174 Co-authored-by: Bruno Casali <[email protected]>
2 parents abd5611 + 1fa489f commit 35b6f4b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
landing_getting_started_1: |-
2+
```yml
3+
# Configure your entities by adding them in config/packages/meili_search.yaml
4+
meili_search:
5+
url: 'http://127.0.0.1:7700'
6+
api_key: 'masterKey'
7+
indices:
8+
- name: movies
9+
class: App\Entity\Movie
10+
```
11+
12+
```php
13+
<?php
14+
// src/Controller/MoviesController.php
15+
namespace App\Controller;
16+
17+
use App\Entity\Movie;
18+
use Doctrine\Persistence\ManagerRegistry;
19+
use Symfony\Component\HttpFoundation\Response;
20+
21+
class MoviesController extends AbstractController
22+
{
23+
#[Route('/add-movies', name: 'addMovies')]
24+
public function addMovies(ManagerRegistry $doctrine): Response
25+
{
26+
$entityManager = $doctrine->getManager();
27+
28+
$movies = ['Carol', 'Wonder Woman', 'Life of Pi', 'Mad Max: Fury Road', 'Moana', 'Philadelphia'];
29+
30+
foreach ($movies as $title) {
31+
$movie = new Movie();
32+
$movie->setTitle($title);
33+
34+
$entityManager->persist($movie);
35+
}
36+
37+
// Inserting data in your DB table will automatically update your Meilisearch index
38+
$entityManager->flush();
39+
40+
//...
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)