Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Doctrine DQL

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Look, I know you already understand how to do queries in SQL - maybe you dream of JOINs, orders and sub-queries. That's really dorky, but I get it. But when you look at Doctrine, it's totally different - with its DQL and its query builder, with their own ways of doing joins, and this hydration of objects thing.

But did you know you can write native SQL queries in Doctrine? Yep! And you can opt in or out of any of its features. Use more of them in one place, where life is easier or when you're feeling like a Doctrine pro. Then go simpler and use less when things get tough or you need to squeeze out ever ounce of performance.

We'll learn about all of that. And don't worry - if you're good at SQL, you're going to be great at writing queries in Doctrine.

Query for Fortune Cookies

Our app is a Fortune Cookie inventory system. Yep, we've finally hit the big time: working for a company that can tell you your future, wrapped up inside a cheap cookie shell.

There are six different fortune categories that are loaded from the database. And if you click on any of these, we see all of the fortunes for the category and how many have been printed.

The project is a small Symfony app - but all the Doctrine stuff translates to any app using the Doctrine ORM. We have 2 entities: Category and FortuneCookie:

... lines 1 - 7
/**
* Category
*
* @ORM\Table(name="category")
* @ORM\Entity(repositoryClass="AppBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="iconKey", type="string", length=20)
*/
private $iconKey;
/**
* @ORM\OneToMany(targetEntity="FortuneCookie", mappedBy="category")
*/
private $fortuneCookies;
... lines 43 - 111
}

... lines 1 - 12
class FortuneCookie
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="fortuneCookies")
* @ORM\JoinColumn(nullable=false)
*/
private $category;
/**
* @var string
*
* @ORM\Column(name="fortune", type="string", length=255)
*/
private $fortune;
... lines 38 - 174
}

With a ManyToOne relation from FortuneCookie to the Category:

... lines 1 - 12
class FortuneCookie
{
... lines 15 - 23
/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="fortuneCookies")
* @ORM\JoinColumn(nullable=false)
*/
private $category;
... lines 31 - 174
}

For our homepage, we're using the entity manager to fetch the Category's repository and call the built-in findAll function:

... lines 1 - 10
/**
* @Route("/", name="homepage")
*/
public function homepageAction()
{
$categoryRepository = $this->getDoctrine()
->getManager()
->getRepository('AppBundle:Category');
$categories = $categoryRepository->findAll();
return $this->render('fortune/homepage.html.twig',[
'categories' => $categories
]);
}
... lines 26 - 47

This returns every Category, and so far, it lets us be lazy and avoid writing a custom query. The template loops over these and prints them out. AMAZING.

Doctrine Query Language (DQL)

Time to write a query! One that will order the categories alphabetically. Call a new method called findAllOrdered():

... lines 1 - 13
public function homepageAction()
{
$categoryRepository = $this->getDoctrine()
->getManager()
->getRepository('AppBundle:Category');
$categories = $categoryRepository->findAllOrdered();
... lines 21 - 24
}
... lines 26 - 47

This needs to live inside the CategoryRepository class. So create a public function findAllOrdered(). To prove things are wired up, put a die statement:

... lines 1 - 12
class CategoryRepository extends EntityRepository
{
public function findAllOrdered()
{
die('this query will blow your mind...');
}
}

Refresh! Sweet, ugly black text - we're hooked up!

Ok, so you're used to writing SQL, maybe MySQL queries. Well, Doctrine speaks a different language: DQL, or Doctrine Query Language. Don't worry though, it's so close to SQL, most of the time you won't notice the difference.

Let's see some DQL. So: $dql = 'SELECT cat FROM AppBundle\Entity\Category cat';:

... lines 1 - 12
class CategoryRepository extends EntityRepository
{
public function findAllOrdered()
{
$dql = 'SELECT cat FROM AppBundle\Entity\Category cat';
... lines 18 - 21
}
}

The big DQL difference is that instead of working with tables, you're working with PHP classes. And that's why we're selecting from the full class name of our entity. Symfony users are used to saying AppBundle:Category, but that's just a shortcut alias - internally it always turns into the full class name.

The cat part is an alias, just like SQL. And instead of SELECT *, you write the alias - SELECT cat. This will query for every column. Later, I'll show you how to query for only some fields.

Executing DQL

To run this, we'll create a Query object. Get the EntityManager, call createQuery() and pass it in the DQL. And once we have the Query object, we can call execute() on it:

... lines 1 - 12
class CategoryRepository extends EntityRepository
{
public function findAllOrdered()
{
$dql = 'SELECT cat FROM AppBundle\Entity\Category cat';
$query = $this->getEntityManager()->createQuery($dql);
return $query->execute();
}
}

This will return an array of Category objects. Doctrine's normal mode is to always return objects, not an array of data. But we'll change that later.

Let's query for some fortunes! Refresh the page. Nice - we see the exact same results - this is what findAll() was doing in the background.

Adding the ORDER BY

To add the ORDER BY, it looks just like SQL. Add ORDER BY, then cat.name DESC:

... lines 1 - 14
public function findAllOrdered()
{
$dql = 'SELECT cat FROM AppBundle\Entity\Category cat ORDER BY cat.name DESC';
$query = $this->getEntityManager()->createQuery($dql);
return $query->execute();
}
... lines 23 - 24

Refresh! Alphabetical categories! So that's DQL: SQL where you mention class names instead of table names. If you Google for "Doctrine DQL", you can find a lot more in the Doctrine docs, including stuff like joins.

Show me the SQL!

Of course ultimately, Doctrine takes that DQL and turns it into a real MySQL query, or PostgreSQL of whatever your engine is. Hmm, so could we see this SQL? Well sure! And it might be useful for debugging. Just var_dump $query->getSQL():

... lines 1 - 14
public function findAllOrdered()
{
$dql = 'SELECT cat FROM AppBundle\Entity\Category cat ORDER BY cat.name DESC';
$query = $this->getEntityManager()->createQuery($dql);
var_dump($query->getSQL());die;
return $query->execute();
}
... lines 24 - 25

Refresh! It's not terribly pretty, but there it is. For all the coolness, tried-and-true SQL lives behind the scenes. Remove that debug code.

Leave a comment!

53
Login or Register to join the conversation

Hello,
I am going crazy.
I have php 7.2.33 installed.

When I triyed to composer install I get this error
In Process.php line 143:

[TypeError]
Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in C:\go
pro doctrine\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php on line 455

Thank you in advance

Reply

Hey zahariastefan462

Sorry for the late response, it seems that there is some incompatibility in Sensio bundle and your composer version. Can you try to downgrade composer to version 1 with composer self-update --1 and try installation process again.

Cheers!

1 Reply

Thank you for the response, I'll try then tell you

Reply
Roozbeh S. Avatar
Roozbeh S. Avatar Roozbeh S. | posted 1 year ago

Hi Ryan, I'm very beginner in Symfony! I have 2 questions here:

1-My PHP version is 7.3.24 and this project support PHP version("php": ">=5.3.3, <7.3.0")!
Do I need to downgrade my PHP version or modify composer.json PHP version?

2-I have opened the start project inside The"Go Pro with Doctrine Queries" but below setup is quite unclear to me!
Would you please explain to me what should I do?

Project Setup:
Configure parameters.yml:
Copy app/config/parameters.yml.dist to app/config/parameters.yml and configure any of the database_ options.

Thank you

Reply
Roozbeh S. Avatar

oh, I see my questions have been already answered below!
So if I understand it correctly, this is quite old project and needs to be upgraded but still good to watch.

Reply

Hey Roozbeh,

Good catch! I'm glad you found the answers below by yourself :) If you still have any questions following this course - please, let us know in the comments and we will help you.

> So if I understand it correctly, this is quite old project and needs to be upgraded but still good to watch.

Yes, you're right! There're 2 ways:
1) Downgrade your PHP version to 7.2 for example so that you could follow this course. You can keep the current PHP version you have and try to install an alternative legacy version instead that you will use to follow this tutorial

2) Download the course code, go to start/ directory, and upgrade the dependencies with "composer update" command so that it would support a higher version of PHP, e.g. 7.3 you have installed. But it may require some extra work and if you're a "very beginner" - it might be a bit tricky for you.

So, I'd suggest you to go with the 1st option. Meanwhile, we're going to release an upgraded tutorial for this topic in the future, but unfortunately I don't have any estimations yet when it might be released.

I hope this helps!

Cheers!

Reply
Roozbeh S. Avatar
Roozbeh S. Avatar Roozbeh S. | victor | posted 1 year ago

Sure Victor,
Thank you

Reply
Paul D. Avatar
Paul D. Avatar Paul D. | posted 1 year ago

Hi, i was wondering if you had an update on your previous reply to Jay. I would love to do this course, but I'm not able to because of the outdated code. Any estimate when an updated course is available? Learning Symfony is not complete without Doctrine Queries

Reply

Hey Paul D.!

Yes! We *have* finished sorting out the dependency issues and each tutorial now advertises (when you hover over the download) which versions of PHP it supports. Unfortunately, this tutorial requires PHP 7.2 or lower - we would have to upgrade the dependencies way too much (and potentially causing the code ti start behaving differently than the video) to get support for higher versions.

So, for now, I don't have a great answer - I apologize :/. The content in the video still works - this part of Doctrine has not changed. But, if you want to download the course code and code along, you'll have to do that using PHP 7.2 or lower. I'll talk with the team: we may do an update on this tutorial to extend its life. I agree with you: it's a critical topic.

Cheers!

Reply
Paul D. Avatar

thanks for that Jay

Cheers,
Paul

Reply
James M. Avatar
James M. Avatar James M. | posted 2 years ago

I cannot get this project started. The starting code gives me an error on composer install

On composer update is the same error.

Here is the stack trace.

[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:

Deprecated: Array and string offset access syntax with curly braces is deprecated in /Users/Jay/Documents/symfony/doctrinepro/start/vendor/symfony/symfony/src/Symfony/Component/Yaml/Unescaper.php on
line 70

Cannot load Zend OPcache - it was already loaded
PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in /Users/Jay/Documents/symfony/doctrinepro/start/vendor/symfony/symfony/src/Symfony/Component/Yaml/Unescaper.ph
p on line 70

[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Reply

Hey James M.!

Bah, sorry about that! You're totally right - the problem happens with PHP 7.3 and 7.4. Basically, when those versions of PHP came out, there we some slight changes that caused breakages in some of our dependencies. This caught us a bit by surprise, and we're still putting systems into place to catch this and fix existing tutorials. We've also updated the dependencies for many tutorials to bring in newer versions that work with PHP 7.3 and 7.4.

In this case, this tutorial is (unfortunately) quite old - so old that we can't update its dependencies without making *major* changes :/. The reason the tutorial is old is that the Doctrine query logic hasn't changed in awhile - so there wasn't a good reason to update. But, this has forced our hand. Unfortunately, for the few tutorials that are in this situation, we're still catching up with wither (A) re-recording them or (B) at least communicating the PHP incompatibilities.

That's a LONG way of saying (A) you're right and (B) it's our fault. We're working to make this *not* a problem (and very transparent where it is a problem), but that's ongoing. My apologies! For this tutorial, the only solution currently is to use PHP 7.2 or lower, unfortunately. Or you can "steal" the code and put it into a newer project - I'd be happy to help if you have any issues.

Cheers!

Reply
Helmi Avatar

Is there a way to see the full sql with parametres of doctrine query in command(ContainerAwareCommand), something like queries in profiler ?

Reply

Hey Helmi

There are two ways you can see your queries being executed:
1) Activate MySql logging. It will slow down your application but for dev purposes it should be good enough - https://stackoverflow.com/a...
2) Run your commands passing in -vvv flag.

Cheers!

1 Reply
Jeffrey C. Avatar
Jeffrey C. Avatar Jeffrey C. | posted 3 years ago

Hi!

When i run composer install after i setup the parameter.yml I get the following error.

https://imgur.com/a/0pVrqAc

And i don't get why i get this error because i just followed the README

Reply

Hey Emin,

Hm, could take a look at this thread? https://symfonycasts.com/sc...

Does it help you to fix this problem?

UPD: Or you know what, just try to run "composer update" first. Actually, I had the similar error for this course and "composer update" helped me. I also pushed changes, so when you download this course again it will contain updated dependencies and this error should be gone.

Cheers!

Reply
Jeffrey C. Avatar
Jeffrey C. Avatar Jeffrey C. | victor | posted 3 years ago

Hey Victor,

Thank you for the fast reply.
When I redownload the course code i get the same error. And when I i run composer update i get the following error.

https://imgur.com/a/RIbURoj

So i think i made it worse. And i have the same problem with the Ansible course.

Kind regards

Emin

Reply

Hey Emin,

Oh, interesting... I did it yesterday and it worked perfect for me. Let's try to figure it out. What PHP version do you have?

Cheers!

Reply
Jeffrey C. Avatar
Jeffrey C. Avatar Jeffrey C. | victor | posted 3 years ago

Hi Victor,

I have currently php 7.3.

Cheers!

Reply

Hey Emin,

Aha, I tested it on PHP 7.2. So, the problem in PHP 7.3. Actually, if you google this error message - you will see some search results for PHP 7.3. So, there're a few possible solutions:
- You can downgrade your PHP version to 7.2
- Or try to debug further and find the problem in code. If it's a custom code - you can easily fix the problem, but if it's a code in vendor/ directory - you can try to upgrade related dependency to the latest version. But sometimes in order to do so - you need to upgrade more related dependencies that's not an easy task and may require some changes in the code. It looks related to Doctrine, see these issues:
- https://github.com/symfony/...
- https://github.com/doctrine...

So I can recommend you to try to upgrade Doctrine ORM first to the latest available version, it should fix the problem.

This tutorial is kinda old already, so it may not work on the latest version of PHP, because 7.3 was released less than month ago.

Cheers!

Reply
Jeffrey C. Avatar
Jeffrey C. Avatar Jeffrey C. | victor | posted 3 years ago

Hey Victor,

thank you for the help men bij downgrading to php 7.2 it works now i don't get the error anymore. But i still want to try to make it work on php 7.3 but for now i will keep it at php 7.2.

Cheer!

Reply

Hey Emin,

Glad it works! Yeah, totally agree, downgrading PHP versions is a bummer! So, when you're ready - try to upgrade dependencies to the latest versions, we lock minor/major versions in composer.json so you can upgrade easily without BC breaks. But you can manually tweak those minor/major version constraints to allow upgrading to the latest available version, but you probably also will need to do some changes in the project.

Or you can create a totally new project on the latest Symfony and try to follow this tutorial on it. Well, you would probably need to add some code, but most of it is just a copy/paste from the downloaded code I think.

Cheers!

Reply
Default user avatar

Hi guys!
I have a problem with the course code and its installation.
Fatal error: require_once(): Failed opening required 'C:\OpenServer\domains\startdoc\app/bootstrap.php.cache' (include_path='.;c:/openserver/modules/php/PHP-7.0-x64;c:/openserver/modules/php/PHP-7.0-x64/PEAR/pear') in C:\OpenServer\domains\startdoc\app\console on line 10

How can I fix this error?

Reply

Hey Nina!

I believe you forgot to run "composer install"

Reply
Default user avatar

Is there a PHPStorm plugin that helps me with my DQL queries? It looks like it's interpreting it as regular SQL which is not helping very much :)

Reply

Hey Johan,

Use the same Symfony plugin for PhpStorm - it should help with it a bit, at least it helps with doctrine query builders.

Cheers!

Reply
Default user avatar

Ye I noticed :)

It does not help with DQL queries, but indeed it helps with the query builders which I will probably be using most of the time.

Thanks Victor!

Reply
Default user avatar

Hello
After configuring paramaters.yml and installing composer, I am unable to start the server or create the database. The error message is:

[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: A non-numeric value encountered

I should note: Before this course I was going through the Symfony 3 path and I believe this course is in Symfony2. So I suspect that may be part of the problem. Any help getting passed this issue would be greatly appreciated.

Dank

Reply

Hey @John

You are correct, this project runs on Symfony 2.6. I believe that error you are getting is related to an incompatibility between Symfony2 and PHP7. You are on PHP7, right?
Hmm, try updating your dependencies "$ composer update"

Cheers!

Reply
Default user avatar
Default user avatar argy_13 | posted 4 years ago

Hi guys!
I have a problem with the course code and its installation through terminal in ubuntu!
I follow the instructions of readme file and i got these errors when i tried to run "php composer.phar update
":

1) [Doctrine\Common\Annotations\AnnotationException]
You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1.
2) Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
3) [RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.

i changed the composer.json as you suggest from this link https://github.com/symfony/...

Now i have the following errors:
1) Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
(didn t change from the previous time)
2) [RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
PHP Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in
/home/projects_linux/queries1/app/AppKernel.php on line 6
(these is like the previous but with the AppKernel problem that i have it when i try to use database:create)

Do you know how can i fix it?
Thanks in advanced!!

Reply

Hey argy_13

For point 1): You have to locate your "php.ini" file, run in a terminal "$ php -i", then open it and activate your opcache or zend_optimize (it depends which one you are using), if you are using opcache, you just have to add this two lines to your file:


opcache.enable=1
opcache.load_comments=1


If for some reason you have more troubles doing it, you can follow this guide: http://www.hostingadvice.co...

I believe this should fix your whole problem, but if not, try updating "distribution-bundle" by running:
$ composer update sensio/distribution-bundle

I hope it fix your problem, have a nice day!

Reply
Default user avatar

Thanks for your immediate reply Diego!
Unfortunately, this didn t help me, but because i m using symfony 3 (i am new in this) i found the solution here...
https://stackoverflow.com/q...
so instead of running to the terminal the command that you write in readme file of the course
"php composer.phar install" because it gives me many exceptions
i run the command from the second answer
"composer require doctrine/annotations" and i didn t have none problem!
p.s. of course i reinstall everything from scratch!
But also thank you again for your answer and keep up the wonderful work that you re doing!

Reply

I'm glad to hear that you could fix your problem, let's keep learning :)

Cheers!

Reply
Default user avatar
Default user avatar jian su | posted 4 years ago

Hi guys:

I try to load fixture to 3.1 since this is 2.6. but I am having troubles

Errors message:
[UnexpectedValueException]
Could not determine how to assign category_id to a AppBundle\Entity\FortuneCookie object

Here is my fixtures.yml

AppBundle\Entity\Category:
category_{1..10}:
name: <name()>
iconKey: <name()>


AppBundle\Entity\FortuneCookie:
fortuneCookie_{1..10}:
category_id: '@category_*'
fortune: <sentence()>
createdAt: <datetimebetween(now)>
numberPrinted: <numberbetween(1,10)>
discontinued: <numberbetween(1,10)>

here is my LoadFixture.php


namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Nelmio\Alice\Fixtures;

class LoadFixture implements FixtureInterface
{
public function load(ObjectManager $manager)
{
Fixtures::load(__DIR__.'/fixtures.yml', $manager);
}

}
Reply

Hey Jian,

Looks like you're trying to assign category to nonexistent property `category_id`, use `category` instead:


AppBundle\Entity\FortuneCookie:
fortuneCookie_{1..10}:
category: '@category_*'

Let me know if you still have this error.

Cheers!

Reply
Default user avatar

Ya..category works. But I have create a category_id field and setter inside my Entity. would that works? Or I better off stick with category object instead?

Reply

Hey Jian,

The coolness here is that you don't need to add "category_id" - you operate objects. Since Category is object and you create this type of objects with Alice - you just may set it below for your FortuneCookie entity and Alice make everything for you, i.e. set the whole Category object with FortuneCookie::setCategory(). Of course, you need FortuneCookie::setCategory() setter to make it possible.

Cheers!

Reply
Default user avatar

Hello
Please, can your tell me we why dump() query looks like:
string(105) "SELECT c0_.id AS id0, c0_.name AS name1, c0_.iconKey AS iconKey2 FROM category c0_ ORDER BY c0_.name DESC"
what mean "c0_.id AS id0"?
what is "c0_"?
why it is written this " c0_.name AS name1"?

why dump() query:
$dql = 'SELECT cat FROM AppBundle\Entity\Category cat ORDER BY cat.name DESC';
Doesn't look like for example:
'SELECT id, name, iconKey FROM ORDER BY name DESC'; ?

Reply

Hey Nina,

It's something related to SQL knowledges, i.e. in your example "category c0_" means creating an alias "c0_" for "category" table. So now I can refer to this table by its short alias "c0_" where "c" is the first letter of real table name, and "0" just means an index. If you have a joins, you'll see that tables have different indexes and it makes sense, because you may have table names that start with the same latter like "posts", "products", etc. The same for column names like c0_.name AS name1 where name1 is the field alias. So with these aliases Doctrine reduces the query length - probably not too much important, but I suppose in this way it's easier to transform query builder into raw SQL queries. Actually, it comes from Doctrine internals.

So in shorts, Doctrine uses SQL aliases because it's a good practice to use them and because it's easier to automate transformation of query builder into raw SQL queries. And probably you won't need to see those raw SQL queries, maybe just for debugging, but it's really rare case.

Cheers!

Reply
William D. Avatar
William D. Avatar William D. | posted 4 years ago

Can I use native sql functions on dql?

Reply

Hey William D.

Yes, you can use some of them like COUNT(), etc. but most of them are unavailable out of the box. However, with third-party packages you can add support for more native SQL functions, for example, see https://github.com/beberlei... for more information.

Cheers!

Reply
Default user avatar
Default user avatar Yang Liu | posted 4 years ago

Hi Ryan,
it seems you are using symfony 2.6 for this tutorial. I just watched all of your symfony 3 tutorials and started coding in symfony3, is there a way to use symfony 3 in this project too? I don't suppose change "symfony/symfony": "2.6.*" in composer.json to "symfony/symfony": "3.1.*" will do the trick?

Reply

Hi Yang!

It's not *quite* that simple, but it almost is :). But first, even though this is on 2.6, there should be much/any difference between this project and Symfony 3. But, if you want to upgrade, you should:

A) Make the above change in composer.json. You could also, optionally, upgrade any other dependency versions to what the Symfony Standard edition uses in its latest version: https://github.com/symfony/...

B) Run composer update

And, that *might* work, except that you won't have the new "3.0" directory structure (e.g. app/console converted to bin/console). If you're *really* interested, you can check out: http://knpuniversity.com/sc...

Alternatively, if you want to code along in Symfony 3, you could start a fresh Symfony3 project and steal important bits of code from this project. I bet you'd learn a few cool things either way :).

Cheers!

Reply
Default user avatar

yeah thanks, I tried to composer update first, but running into some issures and the whole project just broke... and of course there are the issures you mentioned (bin/console and the new var directory). Now I started a new symfony 3 project from scratch und c&p the files (I hope I got them all). It's working for now at least^^

Reply

Sweeeeeet! Happy it's working! If you missed any files, I think it'll be obvious when you get there :).

Good luck!

Reply
Default user avatar
Default user avatar Евгений Явгель | posted 4 years ago

Hi guys!!! I have the same problem as argy_13. But when I try to fix this problem (1 - composer require --dev phpdocumentor/phpdocumentor or 2 - composer require doctrine/annotations) it didn't help me (( I still have problem [Symfony\Component\Debug\Exception\ContextErrorException]
Warning: A non-numeric value encountered Do you know how can i fix it?

Reply

Hey @Евгений Явгель:disqus!

Hmm, let's see :). First, just in case, try a full composer update. Are you using PHP 7.1? It's possible that some library has an incompatibility with a newer PHP version, and running composer update may download a newer, compatible version.

But if that doesn't work, can you send a screenshot of the error? I'm curious what the stacktrace looks like and exactly what part of the code is throwing that error.

Cheers!

Reply
Default user avatar
Default user avatar Евгений Явгель | weaverryan | posted 4 years ago

Yes, I'm using PHP 7.1 and YES you are right: 'composer update' resolved my problem completely. Thanks for your immediate reply !!!

Reply

Woohoo! And thanks for letting me know that fixed it! :)

Reply
Default user avatar
Default user avatar Andrew Grudin | posted 4 years ago

May I download start code for the app(Fortune Cookie) from somewhere?

-1 Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This course is built on Symfony 2, but most of the concepts apply just fine to newer versions of Symfony. If you have questions, let us know :).

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=5.3.3, <7.3.0",
        "symfony/symfony": "2.6.*", // v2.6.13
        "doctrine/orm": "~2.2,>=2.2.3", // v2.4.8
        "doctrine/doctrine-bundle": "~1.2", // 1.6.4
        "twig/extensions": "~1.0", // v1.5.4
        "symfony/assetic-bundle": "~2.3", // v2.8.2
        "symfony/swiftmailer-bundle": "~2.3", // v2.3.12
        "symfony/monolog-bundle": "~2.4", // v2.12.1
        "sensio/distribution-bundle": "~3.0.12", // v3.0.36
        "sensio/framework-extra-bundle": "~3.0", // v3.0.29
        "incenteev/composer-parameter-handler": "~2.0", // v2.1.3
        "hautelook/alice-bundle": "0.2.*" // 0.2
    },
    "require-dev": {
        "sensio/generator-bundle": "~2.3" // v2.5.3
    }
}