Joyful Development with Symfony 3

Ready to get serious with Symfony? You've come to the right place!

Get your first application off on the right foot by coding along with a real application, using the right tools and learning the best practices from the lead author of the Symfony documentation. These fundamentals will get you ready for everything else you'll need to do with Symfony in the future.

In this screencast, we start building an application from the ground-up, exploring the most fundamental parts of the application:

  • Installation and Setup
  • Route Essentials
  • Mastering Controllers & Response
  • Services and the Container
  • Twig
  • JSON Responses
  • Configuration and Environments

... and other goodies mixed in.


Your Guides

Ryan Weaver Leanna Pelham

Questions? Conversation?

  • 2017-04-21 Victor Bocharsky

    Hey Oscar,

    Take a look at this comment where Ryan explain how to fix it: https://knpuniversity.com/s...
    If you still have any questions, do not hesitate to ask again.

    Cheers!

  • 2017-04-20 Oscar Sunrise

    Hi, I can not get the issue with the timezone warning fixed while installing on mac. Is there a tutorial how to handle the change in the php.ini?

    Warning: date_default_timezone_get(): It is not safe to rely on the system'  
    s timezone settings. You are *required* to use the date.timezone setting or
    the date_default_timezone_set() function. In case you used any of those me
    thods and you are still getting this warning, you most likely misspelled th
    e timezone identifier. We selected the timezone 'UTC' for now, but please s
    et date.timezone to select your timezone.
  • 2017-04-14 Victor Bocharsky

    Hey James,

    We're using ZenstruckRedirectBundle on KnpU to handle 404s and redirects.

    We have a whole track "Learn REST": https://knpuniversity.com/t...
    If you want to start with it, you can look at section for beginners: https://knpuniversity.com/t...
    After those courses (or if you already know some basic REST concepts) you can go further with "REST in Symfony": https://knpuniversity.com/t...

    Cheers!

  • 2017-04-14 Victor Bocharsky

    Hey James,

    I really was wondering about your question which is really good, so I did some research and found more tools for myself, and I think it could be helpful for you too, Take a look at those repository:
    https://github.com/h4cc/php...
    https://github.com/exakat/p...

    I'm not dig into these tools yet except those I already mentioned in my previous comment, but some tools are pretty popular.

    Cheers!

  • 2017-04-14 James Davison

    Is there any recommended bundle to use for url rewrite management? Or maybe an "easy" way to filter each url coming in, check if a redirect exists then redirect or not the user?

    Which course is the best to start with Api?

    Thanks loads!

  • 2017-04-14 James Davison

    Thanks a lot!

  • 2017-04-14 Raphaï

    Very nice presentation :)

  • 2017-04-10 Victor Bocharsky

    Hey James,

    Well done, congrats with your first Symfony app! ;) There're a few tools which you can use:
    - Check your PHP project for known security issues: https://security.sensiolabs...
    - Add PHP Coding Standards Fixer to your CI workflow: http://cs.sensiolabs.org/
    - Check your code coverage with PHPUnit, which can generate code coverage information in different formats including HTML: https://phpunit.de/manual/c...
    - You can execute different linter commands from the Symfony console to validate your xml/yaml/twig files

    There's also a few tools you could be interested in:
    https://phpmd.org/rules/ind...
    https://github.com/squizlab...

    You can take a look at Scrutinizer CI. IIRC, it's paid, but free for open source projects. This tool allows you to automate code quality tracking.

    Cheers!

  • 2017-04-10 James Davison

    Just finishing my first web app with Symfony and was wondering what was the best to test it, or/and if there was a good bundle to check the code quality and/or security issues? Any recommendations?

    Thanks

  • 2017-03-22 Abhishek Chaurasia

    thank u sir for your help

  • 2017-03-22 Victor Bocharsky

    Hey Abhishek,

    You can see the "Download" button on each chapter page. But this feature available only for users with active subscription.

    Cheers!

  • 2017-03-22 Abhishek Chaurasia

    how can i download these videos

  • 2017-02-20 Victor Bocharsky

    Hey Hurry,

    Sure, I can! First of all, Drupal 8 does not use Symfony framework but uses its components. What exactly components - you can see here: http://symfony.com/projects... . But if you also want to know what version of component, then you can check the composer.lock file, e.g. Durpal 8.4 uses symfony/console component v2.8.16. So just check *your* current composer.lock file.

    Btw, we have a special track for Drupal 8 users on KnpU: https://knpuniversity.com/t... , so I'd recommend to you to start from there.

    Cheers!

  • 2017-02-18 Harry

    Hi,

    Could you please guide me a little bit by letting me know what version of Symfony Drupal 8 uses? Should I learn Symfony2 first before jumping into Symfony3?

    I am very interested in becoming a Drupal 8 developer but don't know exactly what version of Symfony I should start with.

    Thanks in advance!

  • 2017-02-09 Victor Bocharsky

    Hi Ivan,

    That's a good question! Well, if you already have a Symfony 2 application which you're going to maintain - I'd say better to start with Symfony 2 course, and only then switch to the Symfony 3. But if you're want to start from scratch - then definitely choose the Symfony 3 one. Of course, some topics in these courses partially overlap, but anyway, all those are hold a useful information, so just give both a try.

    Cheers!

  • 2017-02-09 Ivan

    Hi!
    There are two courses "Starting in Symfony 3" and "Starting in Symfony 2". What's the better way to learn them? Should I start with Symfony 2 course first or I may only study a newer one?
    Maybe an older course contains some valuable tips & tricks that will help me in future. I'm confused a little bit :)

  • 2017-01-30 weaverryan

    Hey Rolando!

    Fortunately, there's not much difference between 2.8 and 3.0 (or 3.1, the latest right now). In fact, 2.8 and 3.0 have the *exact* same features, the only difference is that any old/deprecated features in 2.8 were removed in 3.0. So, this means that you can use the code from a 3.0 project on a 2.8 project. The biggest visible difference between the versions is the official directory structure (https://knpuniversity.com/s.... The change is really superficial, and if you're aware of it, you will be able to translate between the 2 versions quite easily.

    If you have any other questions, let us know!

    Cheers!

  • 2017-01-30 Rolando Payán Mosqueda

    Hello, I am currently working with Symfony 2.8, I would like to learn this last version (3.0.0), so my question: what differences are there between these two versions that when learning something in 3.0.0 I can to confuse with 2.8. Greetings

  • 2017-01-19 Diego Aguiar

    Sure thing!

  • 2017-01-19 weaverryan

    Yo Diego!

    Are you back and doing Symfony stuff again? If you are, I have a question for *you* actually - could you email us at hello@knpuniversity.com (I couldn't find your email).

    Cheers!

  • 2017-01-17 Д. Энхбаяр

    Thanks you very much

  • 2017-01-12 Victor Bocharsky

    Hey Felipe and Levan Lomia ,

    Yes, the JSONView plugin for Google Chrome is exactly what we have in our screencasts!

    Cheers!

  • 2017-01-11 Levan Lomia

    Hello Felipe!
    Thank you very much.

  • 2017-01-06 weaverryan

    koesper It's a good suggestion! We'll keep this in mind in the future - it IS a great way to know that you've got things working :).

    Thanks!

  • 2017-01-06 koesper

    Small suggestion for the 'finish' folder in de zip:
    please include a route to `/` again...
    now the only urls that dont give a 404 are the /genus/octopus and /genus/octopus/notes urls

    otherwise: keep up the good work! this tutorial is awesome

  • 2016-12-15 Victor Bocharsky

    Yes, it's strange. Anyway, I'm glad we fixed it.

    Cheers!

  • 2016-12-15 Shairyar Baig

    I manually added the .htaccess file in git by using the following command

    git add web/.htaccess -f


    This then allowed me to commit the file and then eventually uploaded on heroku when i pushed the code.

    I am also not sure why it was not uploaded, strange.

    Thanks

  • 2016-12-15 Victor Bocharsky

    Great! You're welcome. So how did you upload .htaccess? Manually? I really don't know why it wasn't uploaded with other files.

    Cheers!

  • 2016-12-15 Shairyar Baig

    so I managed to upload the .htaccess file and it works :) many thanks @Victor you are a champ. I am so excited.

  • 2016-12-15 Shairyar Baig

    The Procfile has exactly the same information as yours


    web $(composer config bin-dir)/heroku-php-apache2 web/

    Regarding the .htaccess file inside the web directory i find it strange after checking it now that it did not get uploaded, its not in my gitignore file so i am not sure why i dont see it listed inside my web directory on heroku, i am trying to git add and commit it and all it says there is nothing to commit. I connected with heroku using 'heroku run bash' and when i 'ls -a' in web directory there is no .htaccess file listed, may be thats the problem. I am now wondering how do i upload that :) since after making changes in that and doing git add i dont see anything when i check git status.

  • 2016-12-15 Victor Bocharsky

    OK, that's great it works with /app.php . I'm wondering what's inside this Procfile?

    For my Symfony app on Heroku I see:


    web $(composer config bin-dir)/heroku-php-apache2 web/


    on the https://dashboard.heroku.co... page in the "Free Dynos" section, but I suppose you have the different value there, right? Anyway, I have the default Symfony web/.htaccess in my project and it works fine. Please, double check that you have the same one in "web/" directory of your project with the same content: https://github.com/symfony/...

    Cheers!

  • 2016-12-15 Shairyar Baig

    Okay so I added app.json in root by copying it, removed the Procfile from the root however I did notice now Heroku creates that on its own, I can now access the app from app.php and app_dev.php but not without these two in the URL.

    here is the heroku url: https://calm-island-67386.h...

    if you access it you will see the Forbidden error, however if you add app.php at the end of it, you will see the site appearing perfectly fine.

    The error still says


    [autoindex:error] [pid 115:tid 139695287662336] [client 10.152.74.104:48348] AH01276: Cannot serve directory /app/web/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive

    Do i need to add any .htaccess file in the root to make it work without adding app.php at the end of the URL?

  • 2016-12-15 Victor Bocharsky

    Let me know if it helps.

    Cheers!

  • 2016-12-15 Shairyar Baig

    Many thanks I am looking into the resources you sent through.

  • 2016-12-15 Victor Bocharsky

    It should be located in the root dir of your project, i.e. in the root dir of Git repository. Check the link I sent you before for the detailed Symfony example. Here's a blog post about this app.json file: https://blog.heroku.com/int... and its docs: https://devcenter.heroku.co... . As I understand you even don't need a Procfile, just app.json. Anyway, Symfony Demo project doesn't use Procfile at all.

    Cheers!

  • 2016-12-15 Shairyar Baig

    Hi Victor,

    Many thanks for getting back to me. This is the first time I am deploying to heroku and I am not sure where this app.json is? Is this file created by Heroku? Where can i locate it?

  • 2016-12-15 Victor Bocharsky

    Hey Shairyar,

    Could you double check your Heroku configuration with this one: https://github.com/symfony/... ? Deploying this Symfony Demo to Heroku works fine for me, I think you just have some misconfiguration. If it doesn't help - I'd like to see content of your app.json and Procfile configuration files.

    Cheers!

  • 2016-12-15 Shairyar Baig

    I am not exactly sure where to post this question on KNPU so I am trying here,

    I am trying to deploy the Symfony app built using version 3.1.8 on Heroku and I running into a problem that I am not sure why it is happening.

    So the deployment went fine and the schema update command ran perfectly fine but when i try to access the url i get the error

    Forbidden

    You don't have permission to access / on this server.

    So I opened up a log file and there i see the error message


    Cannot serve directory /app/web/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive

    Then I went through the documentation on Heroku https://symfony.com/doc/cur... and crossed checked the Procfile and I can confirm that the Procfile is as whats mentioned in the documentation but still i cant seem to get rid of this issue.

    I have tried reaching out on Stackoverflow and Symfony irc channel and unfortunately I could not get any help there. I am pretty clueless at this stage as to why is this not working. Any help will be appreciated.

  • 2016-12-12 weaverryan

    Hi Sebastian!

    Ah, I see your point :). We do cover many of these things in the rest of our Symfony tutorials - http://knpuniversity.com/tr... - including forms, Doctrine, event dispatcher, validation, logging, forms, etc. When I say that you know 50% of Symfony, it means that there are conceptually two parts of Symfony: (A) understanding the route-controller-response flow and (B) learning to use whatever individual services that you choose to use. The topics you listed fall into part (B) - and exactly how big Symfony will be depends on what you'll use it for. For example, some people may not use forms, so they won't need to learn to use the form-related services. The second half of Symfony is an opt-in to the menu of features that it has.

    So no, from a learning perspective, you're definitely getting started! But you should also feel good - conceptually, you really *do* know half of Symfony. Then, it's your chance to choose which individual features you want to use and try those. We've tried to cover the most important ones in really good detail in the other tutorials.

    Cheers!

  • 2016-12-12 Victor Bocharsky

    Hey Sebastian,

    We cover topics that you specified in other tutorials. Please, check our "Learn Symfony 3" track: https://knpuniversity.com/t... - where you will find answers on many questions.

    Cheers!

  • 2016-12-12 Sebastian Torres

    it would be goog if you will teach how to design a miniproyect using connections of database , form, validations, login. you taught 5% instead of 50% because you said one of the videos that

  • 2016-12-12 Sebastian Torres

    Hello.
    You said one of the videos "now you know symfony about 50%" something like that but what about databases or forms and the other lot of things? you didn't teach that. You said that symfony is very easy but why you didn't teach how to build a login with a connection of database?

    what about this

    Assetic
    Bundles
    Console
    Databases (Doctrine ORM)
    Debug
    Deployment
    Email
    Event Dispatcher
    Expressions
    Forms
    Front-end
    HTTP Cache
    Logging
    Performance
    Profiler
    Request
    Security
    Serializer
    Service Container
    Sessions
    Testing
    Translation (i18n)
    Validation

    how did you compute about you said? you said -> "now you know 50%"

  • 2016-12-05 weaverryan

    Hi Kalpesh!

    Ah, I think I can help explain this! Symfony is a low-level framework for building customer software by developers. So, it's a bit different than something like Wordpress or Drupal, which can be used by developers, but is also meant to be installed by non-technical (or less technical end-users. If you're building something where Symfony is an appropriate tool, then you will need to use the terminal for various tasks. In fact, many developers prefer to use the terminal versus other methods. So actually, Symfony *does* have an installer, but it's done via the terminal, because that's the preferred way by most Symfony devs. If you're coming from another technology, I realize this might seem strange to you. But my best advice is to embrace the terminal - it's really a necessary tool for developing things in Symfony or with similar tools.

    The official Symfony documentation has a few Windows-specific instructions which you might find helpful :) http://symfony.com/doc/curr...

    Cheers!

  • 2016-12-05 Kalpesh Desai

    Hi thanks so much for reply. I am trying to install symfony in window by comand line. please suggest any forum discussion link steps are given to install symfony in window. apart from this can I ask your development team, why is it like anybody have to install symfony by command promp only? Why symfony installation is not available via browser with some user interface ? most of the application in this industries have a installation process with userinterface and very easy unlike symfony.

  • 2016-12-05 weaverryan

    Cheers Yahya! Thanks for the very nice words - and I'm thrilled about your success! I think you have a point about ReactJS - it's included here in part because we could have chosen anything, but also because React is exciting, so it gets people excited. But jQuery would certainly have been easy to understand. I'm glad it didn't mess you up too badly!

    Keep going and good luck!

  • 2016-12-05 weaverryan

    Hi Kalpesh!

    Symfony also works well on Windows :). But, we *do* show everything being done on a Mac, and sometimes (especially in Windows) things are slightly different. The most important thing in Windows is to make sure that you get a reliable terminal, like cygwin or "git bash". If you have a good terminal, then there should be very few - if any - differences when using Symfony in Windows: you'll download it the same way, you can use the built-in PHP web server in the same way (or use Nginx or Apache if you'd like) and you'll run commands from the terminal in the same way.

    I'm not a Windows expert, but if you run into some specific issues or questions, please feel free to ask them - we'll do our best!

    Cheers!

  • 2016-12-05 weaverryan

    Good idea! Doing exactly that right now :). Cheers back!

  • 2016-12-04 Yahya A. Erturan

    weaverryan Thank you for the course. I was keeping my distance on with Symfony for "past" obvious reasons but finally diving in Symfony with a smile on my face. Your edits on the video (with modal boxes, diagrams, samples) helps a lot to understand it. I did manage to run a demo app with your tutorial based on TV series to alter the code and play around. It worked well. If I may, I have only one suggestion to improve the course. Using React.js made me a little confused as I never used it before. Maybe with a more common library, ok not more common but more easy on starter-level, like jQuery would keep my mood up till the end. Because I attached the latest versions of React and Babel-Core from CDN but it gives error about browser keys. When I replaced them to your exact versions, it worked. Thank you so so much for this tutorial.

    Meanwhile, this tutorial works like a charm with Symfony 3.2

  • 2016-12-04 Kalpesh Desai

    what about window's user ? In tutorial video not mention about windows system.

  • 2016-12-03 Nabil Hichri

    Oh Man !! I didn't see it !! it wasn't really so clear may be it shoud be a "btn btn-success btn-lg" download button. Cheers. :)

  • 2016-12-03 weaverryan

    Hey Nabil!

    Ah. thanks man! It does mean a lot to us, seriously :).

    About the code download, you can download it on any video page (e.g. https://knpuniversity.com/s... - click "Download" in the upper right, then click"Course Code" below that. This will contain a zip file with a "start" and "finish" directory. Anyone (subscriber or not) can download the code for this course (because it's free), but only subscribers can download code for other, non-free courses.

    Let me know if that helps! And Cheers!

  • 2016-12-03 Nabil Hichri

    Hi , There . First of all , i would thank you for your ecxellent courses , You're doing an awesome work ( dont be shy ... :p ) . Second , to follow your courses i need to download your code, i did a lot of search to find it but without result. Could you help please !!! Thx .

  • 2016-11-29 weaverryan

    My pleasure :). And thanks for the kind words!

    P.S. Your English seems pretty great to me!

  • 2016-11-29 Abou

    This is exactly what I supposed.
    Thank you...

    By the way I wanted to thank you so much for beeing so kind ! I mean IT !
    You spend so much time to find solutions and answers for everyone ! You saved me soooo much time and YOU gave me access to the Symfony World.
    I promise I will subscribe to a yearly account at next january !

    You are a bright example of what should be the Open Source Community.

    Cheers !
    Abou

    P. S. : I'm so sorry for my poor english... I'm a moroccan who lives in France...

  • 2016-11-29 weaverryan

    Hi Abou!

    YES it is POSSIBLE ;). First, the installer isn't anything special - it's just a small utility that downloads a Symfony app. You will only ever use it once, to start your project. Then, you can safely transfer your files anywhere you want afterwards! Everything exists in your one directory (there is really nothing "installed" - it's all in your project directory).

    So, absolutely - you can upload your local Symfony project to your remote server :). However, there are a lot of files, so FTP is probably a pretty slow way to do it. And also, not having SSH access is far from ideal - I would recommend finding a host that *does* have SSH if possible. The reason is that after you upload your files, there are a few tasks you should run: http://symfony.com/doc/curr.... If you *really* don't have SSH access, then you can try just doing this:

    1) Uploading all the files
    2) Emptying the var/cache directory (this is basically the same bin/console cache:clear --env=prod)

    And that's it! Of course, there are a few other small details, like making sure your var/cache directory is writeable. And, you won't be able to use the normal Doctrine migrations system (since you need SSH access to run that command)... but yes, it is possible. But, better that you find a server with SSH!

    Cheers!

  • 2016-11-29 Abou

    Hi Ryan,

    I'm wondering if it is possible to install symfony without the installer.
    I mean let's suppose I have the next situation to handle :

    1 - I only have an ftp access to a remote linux server.
    2 - I can tweak and handle the apache config to set the virtualhosts.

    So is it possible to upload a local symfony project (created according to the standard way) to my remote web server and hit the road :) ?...

    I suppose I will have to modify some pathes, some config para...

    I am asking because I want to use Symfony on server where I have no admin right, I don't even have an ssh access

    Best regards,
    Abou

    P. S. : Please say YES it is POSSIBLE ...

  • 2016-11-28 Hakim Ch

    Your the best! thank you <3

  • 2016-11-28 weaverryan

    Yo Hakim Ch!

    Cool question :). I would always says if you're learning so that you can program something or be valuable for the job market, use the latest version of Symfony. If you use Symfony 3.2 for example (which will be released in a few days), then you will be equally qualified to work on a Symfony 3 project or Symfony 2.8, if you find a company using it. You could then study our upgrade guide (http://knpuniversity.com/sc..., but in reverse to know what what the old changes are. But if you know Symfony 3, you are fully qualified to work on Symfony 2.8 - and you can tell them I said so :p.

    Cheers!

  • 2016-11-27 Hakim Ch

    Hi! i have a question!
    wich the best version for job market needs. 2.8 LTS or 3 Stable ?

  • 2016-11-03 Victor Bocharsky

    You're welcome!

    Cheers!

  • 2016-11-03 Женя Федоров

    Thank you very much!

  • 2016-11-01 Vince Liem

    I can not thank you enough for also giving an example of JSON and reactJS, totally loving it.

  • 2016-10-18 weaverryan

    Hey Jurgen!

    I can hopefully give you a few tips at least :). First, technically, you can run Symfony just fine on Windows. I say "technically", because there are a few subtle things that will be different... which are no big deal... except that they can definitely trip you up while you're learning. If you're hitting some issues, I would be happy to help you through those.

    But, having a VM is obviously a really nice way to go as well. But, it can be tricky in its own way. I would recommend trying out Homestead: it's a really nice VM that works with Symfony, Laravel and other PHP environments really well: https://laravel.com/docs/5..... It will still possibly be tricky - things are always a bit different on Windows. Treehouse has a tutorial about Homestead in Windows (though it's a bit out of date): http://blog.teamtreehouse.c....

    As always, feel free to posts questions here! Unfortunately, I don't have enough Windows experience to be able to give you an exact, best path. But, while using Windows isn't the most-common use-case, many people pull it off just fine (but setup *can* be frustrating).

    Cheers!

  • 2016-10-18 Jurgen Verhasselt

    Hi, does anyone have a truly virtual machine with windows 7 or later with phpstorm and symfony and everything, I have setup a W7 machine but half of the course (like routing and other things) i cannot pratice as my environment is not setup properly and I am too much a newbie, spent already more time trying to fix the setup than learning to program, anybody can help me?

  • 2016-09-27 Thierno Diop

    Thx a lot

  • 2016-09-26 weaverryan

    Hi Thierno!

    I never worry about performance for frameworks - they're all optimized and can be optimized. Your app will be slow or fast because of the code your write :). So, I can tell you that Symfony is really fast, but so is Rails :).

    Second, about rapid-application-development, I'm not sure because I don't have a lot of experience in Rails. Symfony is not the most RAD framework, however, it gives more emphasis to "best practices" so that you can build a codebase that's maintainable and has less WTF-moments. There's definitely a trade-off between RAD and a framework that is predictable.

    Cheers!

  • 2016-09-26 Thierno Diop

    Hi ryan what do you think about the comparaison of symfony and rails in term of performance and rapidy of développement thxxx

  • 2016-07-19 Luciano Marinho

    Thank you Victor =)

  • 2016-07-19 Victor Bocharsky

    Hey Luciano!

    Yes, you can check the Symfony Fundamentals: Bundles, Configuration & Environments next.
    A list of all subsequent courses is here: https://knpuniversity.com/t... .

    Cheers!

  • 2016-07-16 Luciano Marinho

    There is a continuation of this tutorial ? Can I give me url to this ? I'll to learn more about symfony and I love this tutorial

  • 2016-07-16 Luciano Marinho

    I can see it. Thanks

  • 2016-07-16 weaverryan

    Hey Luciano!

    If you're a subscriber, you'll see a Download link on the upper right of every video page - for the code. After you unzip the code, there will be a "start" and "finish" directory - both contain the tutorial directory. If you're not a subscriber, you can find the start code here: https://github.com/knpunive...

    I hope that helps!

  • 2016-07-15 Luciano Marinho

    I'm in 9.1 where speak about 'tutorial' directory...but, where is the download link to that files ?

  • 2016-06-26 weaverryan

    Yea, that makes really good sense - and I bet others would also like this! I've added it to our internal list - but it probably won't make it onto the schedule anytime soon, unfortunately - so many things to get to :)

    Thanks for the details on this!

  • 2016-06-24 Reynier Pérez Mira

    Hi there weaverryan the problem is not the link getting old but poor information. This video is only for Routing stuff but what about databases? configuration? everything else? I've been looking around for a while and I did found a few links from StackOverflow and OctiviLabs (http://labs.octivi.com/data... ) and also, maybe, some helpful bundles https://github.com/tahoelim... but is not helpful at all. I would like to see something for newbies a simple application sharing same code but multi-tenancy databases in order to understand how to handle this part using Symfony. What do you think?

  • 2016-06-24 weaverryan

    I think we might be able to do this :). Tell me, this link is a bit old, but how far does this go to help you? Or are you after something else entirely? https://knpuniversity.com/s...

  • 2016-06-23 Reynier Pérez Mira

    weaverryan would be possible to have kind of tutorial for a multi-tenancy application using Symony2|3? That would be great and I am looking to it but so far docs on Internet are not good enough, so what you think?

  • 2016-06-23 Victor Bocharsky

    Great! I'm glad it works. :)

    OK, I'll look at it too.

  • 2016-06-23 Sudhir

    hey Victor Bocharsky
    thanking for replying.
    its working fine now.
    your knp tutorials are awesome.

    however i have posted one another question at https://knpuniversity.com/screencast/fosuserbundle-ftw/fos-user-bundle
    would you like to answer pls?

  • 2016-06-23 Robert

    I have managed to fix this, for some reason the cache was not clearing as it supposed to. In such scenarios it is then necessary to delete the whole folder var/cache/prod.

    Regards,

    Robert

  • 2016-06-23 Victor Bocharsky

    Hey, Sudhir!

    For example, you have a file "app.js" in your directory structure like: web/vendor/FOSUserBundle/Resources/JS/app.js. Please, check one more time you are doing it right.

    To include this file in your template, you need to build a correct link to it. The "asset()" twig function helps you here. Put the next code somewhere in your HTML code (probably somewhere in <head> or before a closing </body> tag ):

    <script type="text/javascript" src="{{ asset('vendor/FOSUserBundleResources/JS/app.js') }}"></script>


    NOTE: You don't need to use "web/" prefix in the path, asset() function handle it for you.

    To ensure it works, In your "app.js" you need to write only one single line like:

    alert('Hello FOS!');

    Go to the page where you include this app.js file and let me know if you still don't see the "Hello FOS" alert.

    Cheers!

  • 2016-06-23 Victor Bocharsky

    Hey, Robert!

    You can just do php bin/console cache:clear && php bin/console cache:clear --env=prod. By default, you have the DEV environment in Symfony console.

    It's a bit weird if page works in DEV env and doesn't work in PROD on remote server. Could you try to remove cache folders manually (var/cache/prod and var/cache/dev) instead of using console command? Please, ensure that these folders are gone from cache directory. Does it help?

    From logs I can see that script unable to create "var/sessions/prod" folder. Could you create it manually and see if it helps? Also ensure that "var/sessions/prod" folder is created and you don't have any permission errors.

  • 2016-06-23 Sudhir

    yeah.. sounds very logical.
    so for better directory structure and convenience for UI developer, i make a folder hierarchy as

    web/vendor/FOSUserBundleResources/JS and
    web/vendor/FOSUserBundleResources/ css

    i don't know why.. everything is file but my javascript is not executing. Even i test alert('Hello FOS') but still no response.
    i am still debugging..

  • 2016-06-22 weaverryan

    Hi Sudhir!

    Ok, good question! A few things:

    1) You can't actually edit the FOSUserBundle in your vendor directory - this is 3rd party code - if you modify this directory, you may lose those changes when you upgrade that library in the future (you also typically do *not* commit the vendor/ directory to version control - e.g. git)

    2) But, in general, you have described a very valid question: "How can I put CSS/JS into my bundle, and add a link to it?". I don't recommend doing this anymore - I keep thing simple and put my CSS/JS in the web directory. But, this is entirely subjective: you are certainly free to put CSS/JS into your bundle. The problem - of course - is that your web server sees the web/ directory as your document root. Put simply: nothing outside of web/ is publicly accessible to your user. Fortunately, Symfony has a built-in workaround for this. We talk about it in our Symfony2 series actually: http://knpuniversity.com/sc...

    So yes, it is possible!

  • 2016-06-22 Robert

    Dear Victor,

    Thank you for your hint. I have zipped the directory and unzipped it on the server. Once that is being done I get a blank page when the app.php runs in prod environment with debug being set to false.

    Before putting everything onto the server, I have cleared cache via php bin/console cache:clear & php bin/console cache:clear --env=prod & php bin/console cache:clear --env=dev --no-debug.

    The error log that I am getting is of this manner:

    [22-Jun-2016 12:32:49 America/Denver] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Session Storage was not able to create directory "/home2/howtowit/public_html/howtowit\app/../var/sessions/prod"' in /home/domain/public_html/subdirectoryvendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php:52
    Stack trace:
    #0 /home/domain/public_html/subdirectory/var/cache/prod/appProdProjectContainer.php(2163): Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler->__construct('/home/domain...')
    #1 /home/domain/public_html/subdirectory/var/bootstrap.php.cache(2118): appProdProjectContainer->getSession_HandlerService()
    #2 /home/domain/public_html/subdirectory/var/cache/prod/appProdProjectContainer.php(2202): Symfony\Component\DependencyInjection\Container->get('session.handler')
    #3 /home2/howtowit/public_html/howtowit/var/bootstrap.php.cache(2118): appProdProjectContainer->getSession_Storage_NativeService()
    #4 /home2/howtowit/public_html/howtowit/var/cache/prod/appProdPro in /home2/howtowit/public_html/howtowit/vendor/twig/twig/lib/Twig/Loader/Filesystem.php on line 94

    Using the dev environment everything works fine on the remote server. Similarily, using prod configuration with debug being set false on my localhost works fine.

    What do you suggest?

    Thank you for your input,

    Robert

  • 2016-06-22 Sudhir

    Hi weaverryan

    Please look this scenario.
    in my symfony 2.8 project i have FOSUserBundle under vendor (as we had already discussed in PRE_1 and PRE_2).
    in that bundle i want to put a public folder, which will content my all css and js file (only related to FOSuserbundle) (i want to use this css and js globally for another bundle also )

    i want to reference these js and css in base.html.twig under FOSuserbundle. But unfortunately all link which i am providing is linking to "web" folder. (web/css and web/js)

    i don't want to use this directory. i want to put all my css and js under vendor / pubic/ css and /js

    is it possible ?

  • 2016-06-22 Victor Bocharsky

    Hey, Robert!

    I can give you some advices.

    1) Yes, Symfony has a lot of dependencies, so you can try to zip all files locally, transfer it to the production, and unzip them. But this way you can stuck with server recourses limitation (memory, free disc space, etc). The another option is to transfer all files except "/vendor/" dir and after that run "composer install" on production. Composer installs dependencies more quickly (some packages loads from cache). You could do it even faster, if you have cloned Git repository of your project on production, then you just need to pull changes which need to be deployed and run "composer install" and maybe few more command after it (i.e. run migrations, load or compile your assess, etc.).

    You also can take a look at other deploy tools like Capistrano, but they're more complex to configure. If you are interesting in a more ways to deploy a Symfony application, check How to Deploy a Symfony Application article from Symfony docs.

    2) Yes, you can delete it, but the better option is to make a proper configuration of your production web server (it's possibly Nginx or Apache). You need to point all requests handling with /web/app.php front controller. There're few Symfony docs examples that shows you how to configure it. It you configure it properly, then each request to the "app_dev.php" will be handled with "app.php".

    I hope I help with it.

    Cheers!

  • 2016-06-21 Robert

    Hi Ryan,

    I would like to ask for your thoughts about deploying a ready application from a dev into production on a hosting. The basic Symfony has close to 7000 files in its basic form. It takes 1-2h to transfer it via FTP. Is there any better way of doing this?

    Secondly, in order to disable the dev environment shall I simply delete the app_dev.php once the application is uploaded on the server or is there a different method of doing it?

    Thank you,

    Robert

  • 2016-06-14 weaverryan

    Well, you just made my day! I'm *so* happy you found the tutorials useful and fun *and* that the scripts were helpful! It's really important to us to make those available :). Good luck on your journey - becoming a webdev is not an "easy" task, which is why it's so rewarding.

    Cheers!

  • 2016-06-12 Karlola

    I just flooded another thread here with an unneeded panicking comment, so I want to leave some positivity too :) I am an English-Polish translator desperately trying to morph into a web devel. This course is priceless help after I struggled to understand OOP and SF during a weekend course AND to keep my job. Also, I am a hard-of-hearing person with very little auditory training in English but I absolutely get what you are saying in the witty videos! Thank you for caring about the sound quality and providing the script for those of us who don't even see a point in having headphones at home :)

  • 2016-06-03 Dan Costinel

    Yep, now all things are clear! Thank you!

  • 2016-06-03 weaverryan

    Hi Dan!

    Yes, I know *exactly* why you are confused :). Here's what happened

    1) In all versions of Symfony, there is a web/.htaccess file that tells Apache to *always* use app.php (the prod environment) unless app_dev.php is in the URL. This explains why you would go to http://example.com (after clearing the prod cache) and see your app in the prod environment (with no web debug toolbar).

    2) However, if you use the built-in PHP web server instead of Apache while developing, then Symfony tells the web server to use app_dev.php by default, instead of app.php. So, when you go to localhost:8000, it is actually executing localhost:8000/app_dev.php - this gives you the web debug toolbar.

    So actually, this isn't a difference between Symfony 2 and Symfony 3, however I *do* show the built-in web server a lot more now than I used to :). The basic point is this: if you execute app.php then you are in the "prod" environment. If you execute app_dev.php you are in the dev environment. And if you don't include *either* of these in your URL, then it's up to your web server to decide which to use by default. The built-in PHP web server uses app_dev.php. But you should configure Apache (which will happen automatically thanks to the .htaccess file) or Nginx to use app.php by default in real-life.

    I hope that clarifies!

  • 2016-06-03 Dan Costinel

    Hi Ryan. Can you please answer a question? Before Symfony 3, to access the app in dev mode, I used /app_dev.php/ in front of any exiting and non-existing route, and the web profiler was there to help. When I needed to see the app in prod mode, I deleted the app_dev.php part, I received a 500 Internal Server Error, I cleared the cache for prod env, and then I could see the page in prod mode w/o probs. But now, the things had changed. In the sense that, even if I proceed with those things, when I access the app, in prod mode, the web profiler is still there! And another problem is that if I use a Symfony version < 3, the behaviour is still the same! (the web profiler is still present in prod mode). Any advice?
    Thank you!

  • 2016-06-01 Shairyar Baig

    yup thats what I ended up doing, thanks.

  • 2016-05-31 weaverryan

    Yep, it's likely because of the localhost part - most email providers (like gmail) I believe like to download that image themselves and proxy it to you, so that would fail. Honestly, we often hardcode our production URL for assets in emails (e.g. https://knpuniversity.com/...).

    Cheers!

  • 2016-05-25 Shairyar Baig

    I am working on localhost and the email is being generated via controller, for example when a user registers a welcome email is sent and in that email i am trying to add a logo if i

    dump {{ absolute_url(asset('images/logo.jpg')) }} 

    i see a complete path http://127.0.0.1:8000/images/logo.png but i see no image in email, even if i don’t use an image variable and hardcode the path still i don’t see the image.

    I am guessing it could be because i am on http://127.0.0.1:8000

  • 2016-05-25 weaverryan

    Hey Baig!

    Are you sending the emails via a console command? If so, check this out: http://symfony.com/doc/curr...

    If not, can you see what URL is being generated for your image? Is the hostname correct?

    Cheers!

  • 2016-05-24 Shairyar Baig

    Hi Ryan,

    Is there anything special we need to do when we want to embed image in an email?

    For example if I do

    {{ absolute_url(asset('images/logo.jpg')) }}

    and when i get email all i see is the image holder that generally appears when the image is missing, I looked into the symfony documentation and its doing the same thing so what am i missing here?

    Regards,
    Baig

  • 2016-05-23 kokers

    <3

  • 2016-05-19 Jonathan Keen

    Just a recommendation, cause it drives me nuts sometimes, would be to have a 'PHPStorm setup and go' tutorial for Symfony. Something that goes through path mapping for the built in web server and setting up XDebug. Sometimes I feel like I spend more time getting XDebug to work right then actually using it. Perhaps this could include setting up PHPUnit tests to use XDebug as well.

    Anyways, just a thought. Something you probably do daily but it at times drives me crazy because I feel like I'm never doing it right. lol