-
Notifications
You must be signed in to change notification settings - Fork 30
/
.code-samples.meilisearch.yaml
39 lines (31 loc) · 1.19 KB
/
.code-samples.meilisearch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
landing_getting_started_1: |-
// # Configure your entities by adding them in config/packages/meilisearch.yaml
// meilisearch:
// url: 'http://127.0.0.1:7700'
// api_key: 'masterKey'
// indices:
// - name: movies
// class: App\Entity\Movie
<?php
// src/Controller/MoviesController.php
namespace App\Controller;
use App\Entity\Movie;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;
class MoviesController extends AbstractController
{
#[Route('/add-movies', name: 'addMovies')]
public function addMovies(ManagerRegistry $doctrine): Response
{
$entityManager = $doctrine->getManager();
$movies = ['Carol', 'Wonder Woman', 'Life of Pi', 'Mad Max: Fury Road', 'Moana', 'Philadelphia'];
foreach ($movies as $title) {
$movie = new Movie();
$movie->setTitle($title);
$entityManager->persist($movie);
}
// Inserting data in your DB table will automatically update your Meilisearch index
$entityManager->flush();
//...
}
}