Skip to content

Instantly share code, notes, and snippets.

@IngmarBoddington
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IngmarBoddington/57785a14a069fdd728f7 to your computer and use it in GitHub Desktop.
Save IngmarBoddington/57785a14a069fdd728f7 to your computer and use it in GitHub Desktop.
Symfony Setup / Config / Some Fundamentals
SETUP (Vanilla Demo Install)
Install apc
sudo pecl install apc
Install composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer create-project symfony/framework-standard-edition myproject/ ~2.4
- Example new project through composer
php app/check.php
- Checks environment / current settings
php app/console server:run
- Starts application
app/console --version
- Show Symfony Version
php ./bin/vendors install --reinstall
- "Old install Mech"
-----
STRUCTURE
app <- general app stuff
app/config <- app config, routing
src <- bundles
src/publisher <- dir for bundles from a publisher
src/publisher/bundle <- an actual bundle directory
-----
BUNDLE CREATION
Create (empty) bundle class in root directory, e.g.
// src/<publisher>/<bundle>/<publisherBundle>.php
namespace <publisher>\<bundle>;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class <publisherBundle> extends Bundle
{
}
Add this to app/AppKernel.php e.g. add 'new <publisher>\<bundle>\<publisherBundle>(),' to bundles array
-----
ROUTING
app/config/routing.yml + app/config/routing_dev.yml
- Production and development Request to Controller mapping
Example import of routing from bundle
_<key>:
resource: @<Bundle>/<pathToController>
Example routes
_<key>:
path: <path>
defaults: { _controller: <bundle>:<controller>:<action> }
_<key>:
resource: "@<bundle>/<controller>"
type: annotation
prefix: <prefix>
File structure / Logical Name / namespace relation
e.g. src/Acme/DemoBundle/Controller/DemoController
-> Namespace = Acme\DemoBundle\Controller
-> Bundle = AcmeDemoBundle
Example annotation route (on controller method) (when specified by defined route)
/**
* @Route("/hello/{name}", name="_demo_hello")
* @Template()
*/
//$name can be passed to controller method
//Template() will include template defined by controller / action name
(e.g. src/<pub>/<bundle>/Resources/views/Demo/hello.html.twig)
- Passes values returned from action method to template
Example include in controller (instead of annotation)
$this->render('AcmeDemoBundle:Demo:hello.html.twig', array(
'name' => $name,
));
-----
CONFIG (app/config)
- Routing and config files
- Production and development versions
- Lots of duplication so dev configs should import productions and augment
imports:
- { resource: <resource> }
-----
API Index: http://api.symfony.com/2.5/index.html
-----
TEMPLATES (Twig)
e.g. Logical Name = AcmeDemoBundle:Welcome:index.html.twig
-> /src/Acme/DemoBundle/Resources/views/Welcome/index.html.twig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment