Skip to content

Commit 678bac5

Browse files
committed
Add landing_getting_started_1 code samples
1 parent abd5611 commit 678bac5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

.code-samples.meilisearch.yaml

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

0 commit comments

Comments
 (0)