-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOCSP-39180: Symfony Quick Start #971
Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c327520
DOCSP-39180: symfony qs
rustagir 82ea9e8
wip
rustagir 157f580
wip
rustagir ac04d15
wip
rustagir bddcbaa
wip
rustagir 5465f48
wip
rustagir 8a5a5be
wip
rustagir 24ef1ba
wip
rustagir 3d91667
wip
rustagir 02e77e6
fix error
rustagir a490e74
vale
rustagir a05e2b7
reorg
rustagir 1cc4dcd
add image
rustagir 0178ab7
captions and NR edits1
rustagir 65f7e10
NR edits 1 final
rustagir 4ce9441
edits
rustagir 29e3019
wip
rustagir b30e78f
small fix to note
rustagir 1144580
NR and RB comments
rustagir 7edd4ee
add list item
rustagir f55ff27
JM tech review php
rustagir 6756e75
JM tech review 2
rustagir 1f5d6fd
small fixes
rustagir c052d89
JM tech review 3
rustagir 24a00a9
change color
rustagir b536c70
small fixes
rustagir 56122ae
small fix
rustagir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Document; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
use Doctrine\ODM\MongoDB\Types\Type; | ||
|
||
#[ODM\Document(collection: 'restaurants')] | ||
class Restaurant | ||
{ | ||
#[ODM\Field(type: Type::STRING)] | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public ?string $id = null; | ||
|
||
#[ODM\Field(type: Type::STRING)] | ||
public string $name; | ||
|
||
#[ODM\Field(type: Type::STRING)] | ||
public string $borough; | ||
|
||
#[ODM\Field(type: Type::STRING)] | ||
public string $cuisine; | ||
} |
47 changes: 47 additions & 0 deletions
47
source/includes/php-frameworks/symfony/RestaurantController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use App\Document\Restaurant; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use MongoDB\BSON\Regex; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class RestaurantController extends AbstractController | ||
{ | ||
private DocumentManager $dm; | ||
private LoggerInterface $logger; | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public function __construct(DocumentManager $_documentManager, LoggerInterface $_logger) | ||
{ | ||
$this->_documentManager = $_documentManager; | ||
$this->_logger = $_logger; | ||
} | ||
|
||
#[Route('/', name: 'restaurant_index', methods: ['GET'])] | ||
public function index(Request $request): Response | ||
{ | ||
return $this->render('restaurant/index.html.twig'); | ||
} | ||
|
||
#[Route('/restaurant/browse', name: 'restaurant_browse', methods: ['GET'])] | ||
public function browse(Request $request): Response | ||
{ | ||
$restaurantRepository = $this->_documentManager->getRepository(Restaurant::class); | ||
$queryBuilder = $restaurantRepository->createQueryBuilder(); | ||
|
||
$restaurants = $queryBuilder | ||
->field('borough')->equals('Queens') | ||
->field('name')->equals(new Regex('Moon', 'i')) | ||
->getQuery() | ||
->execute(); | ||
|
||
return $this->render('restaurant/browse.html.twig', ['restaurants' => $restaurants]); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{# templates/restaurant/browse.html.twig #} | ||
|
||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %} | ||
Search Restaurants | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<h1>Search Restaurants</h1> | ||
{% for restaurant in restaurants %} | ||
<p> | ||
<span style="color:green;"><b>Name: </b>{{ restaurant.name }}</span><br> | ||
<b>Borough:</b> {{ restaurant.borough }}<br> | ||
<b>Cuisine:</b> {{ restaurant.cuisine }}<br> | ||
</p> | ||
{% endfor %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,7 @@ | ||||||||
{# templates/restaurant/index.html.twig #} | ||||||||
|
||||||||
{% extends 'base.html.twig' %} | ||||||||
|
||||||||
{% block body %} | ||||||||
<h1>Welcome to the Symfony MongoDB Quickstart!</h1> | ||||||||
{% endblock %} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class alias is no longer used.