<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Setup | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/setup/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Mon, 29 Mar 2021 14:41:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Silverstripe Setup Script</title>
		<link>https://nerdpress.org/2012/02/09/silverstripe-setup-script/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 09 Feb 2012 09:30:42 +0000</pubDate>
				<category><![CDATA[Project Setup]]></category>
		<category><![CDATA[Silverstripe]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Setup]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2041</guid>

					<description><![CDATA[<p>We thought we had to improve our SilverStripe setup script for our development environment. So Max and me rewrote it to add submodules and some other improvements. Just run: and you have silverstripe project folder structure the tutorial theme a already filled git repository sapphire as submodule cms as submodule Uploadify as submodule DataObjectManager as &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/02/09/silverstripe-setup-script/" class="more-link">Continue reading<span class="screen-reader-text"> "Silverstripe Setup Script"</span></a></p>
The post <a href="https://nerdpress.org/2012/02/09/silverstripe-setup-script/">Silverstripe Setup Script</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>We thought we had to improve our <a href="https://nerdpress.org/2011/09/11/install-silverstripe-with-some-modules-from-git/">SilverStripe setup script</a> for our development environment.<br />
So <a href="https://web-development.cc/">Max</a> and me rewrote it to add submodules and some other improvements.</p>
<p>Just run:</p>
<pre class="brush: bash; title: ; notranslate">
./install_silverstripe.sh mynewproject tags/2.4.7
</pre>
<p>and you have</p>
<ul>
<li>silverstripe project folder structure</li>
<li>the tutorial theme</li>
<li>a already filled git repository</li>
<li>sapphire as submodule</li>
<li>cms as submodule</li>
<li>Uploadify as submodule</li>
<li>DataObjectManager as submodule</li>
<li>UserForms as submodule</li>
</ul>
<p><span id="more-2041"></span></p>
<p>What you then still need to do is:</p>
<ul>
<li>create the database</li>
<li>setup a local vhost</li>
<li>open your project url and run the install process</li>
<li>start to code</li>
</ul>
<p>So here it is:<br />
<script src="https://gist.github.com/1768946.js?file=install_silverstripe.sh"></script><noscript><pre><code class="language-shell shell"># install silverstripe + common modules from github
# usage sh install_silverstripe.sh &lt;folder_name&gt; &lt;tag/branch&gt;
# examples: 
# sh install_silverstripe.sh some_folder tags/2.4.5
# sh install_silverstripe.sh some_folder master

#set up project base folder
git clone git@github.com:silverstripe/silverstripe-installer.git $1
cd $1
git checkout $2
#we kill the .git because we want this repo just as starter and init our own repository (instead of export)
rm -rf .git

#set permissions for install
chmod 0777 assets assets/*
chmod 0666 .htaccess mysite/_config.php assets/*/*

git init

git submodule add git@github.com:silverstripe/silverstripe-cms.git cms
cd cms
git checkout $2
cd ..
git add cms
git commit -m &quot;checked out submodule cms to $2&quot;

git submodule add git@github.com:silverstripe/sapphire.git sapphire
cd sapphire
git checkout $2
cd ..
git add sapphire
git commit -m &quot;checked out submodule sapphire to $2&quot;

# add common modules
git submodule add git://github.com/unclecheese/Uploadify.git uploadify
git submodule add git://github.com/unclecheese/DataObjectManager.git dataobject_manager
git submodule add git://github.com/silverstripe/silverstripe-userforms.git userform

git submodule init
git submodule update

git add .
git commit -m &quot;Initial Commit&quot;</code></pre></noscript></p>The post <a href="https://nerdpress.org/2012/02/09/silverstripe-setup-script/">Silverstripe Setup Script</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Symfony 2 &#8220;from scratch&#8221; bootstrappen</title>
		<link>https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/</link>
					<comments>https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 01 Dec 2010 11:52:52 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[Bundle]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1247</guid>

					<description><![CDATA[<p>&#8230; machen wir heute mal, weil die Sandbox komisch ist mit den vielen (ärm &#8211; 2) redundanten /vendor und /wasweißich-Verzeichnissen. Also, bauen wir die Sandbox mal nach: Wir brauchen: Ein halbwegs aktuelles PHP 5.3.x, MySQL 5.x, Apache 2 und git. Dann erstmal den aktuellen Symfony2-Master ziehen&#8230; $ git clone https://github.com/fabpot/symfony.git symfony2test &#8230; und die Vendor-Scripte &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony 2 &#8220;from scratch&#8221; bootstrappen"</span></a></p>
The post <a href="https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/">Symfony 2 “from scratch” bootstrappen</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>&#8230; machen wir heute mal, weil die Sandbox komisch ist mit den vielen (ärm &#8211; 2) redundanten /vendor und /wasweißich-Verzeichnissen. </p>
<p>Also, bauen wir die Sandbox mal nach:</p>
<p><span id="more-1247"></span></p>
<p>Wir brauchen: Ein halbwegs aktuelles PHP 5.3.x, MySQL 5.x, Apache 2 und git.</p>
<p>Dann erstmal den aktuellen Symfony2-Master ziehen&#8230;</p>
<pre class="brush: bash; title: ; notranslate">
$ git clone https://github.com/fabpot/symfony.git symfony2test
</pre>
<p>&#8230; und die Vendor-Scripte installieren:</p>
<pre class="brush: bash; title: ; notranslate">
$ cd symfony2test
$ sh ./install_vendors.sh
</pre>
<p>Nun sollte sich folgendes Verzeichnislayout ergeben haben:</p>
<pre class="brush: bash; title: ; notranslate">
drwxr-xr-x  6 joshi joshi 4,0K 2010-11-30 21:19 .
drwxr-xr-x 22 joshi joshi 4,0K 2010-11-27 16:34 ..
-rw-rw-rw-  1 joshi joshi  998 2010-11-30 21:10 autoload.php.dist
drwxr-xr-x  8 joshi joshi 4,0K 2010-11-30 21:19 .git
-rw-r--r--  1 joshi joshi   34 2010-11-30 15:49 .gitignore
-rwxrwxrwx  1 joshi joshi  840 2010-11-30 21:10 install_vendors.sh
-rw-rw-rw-  1 joshi joshi 1,1K 2010-11-30 21:10 LICENSE
-rw-rw-rw-  1 joshi joshi 1,1K 2010-11-30 21:10 phpunit.xml.dist
-rw-rw-rw-  1 joshi joshi 1,2K 2010-11-30 21:10 README
drwxrwxrwx  3 joshi joshi 4,0K 2010-11-30 21:10 src
drwxrwxrwx  3 joshi joshi 4,0K 2010-11-30 21:10 tests
-rwxrwxrwx  1 joshi joshi  541 2010-11-30 21:10 update_vendors.sh
drwxrwxrwx 11 joshi joshi 4,0K 2010-11-30 21:13 vendor
</pre>
<p>Die Vendor-Scripts liegen zunächst mal im Projekt-Root-Verzeichnis; Dort haben sie aber nichts verloren:</p>
<pre class="brush: bash; title: ; notranslate">
$ mv vendor/ src/
</pre>
<p>Nun haben wir alles, um eine Symfony-App zu erstellen &#8211; das funktioniert momentan aber noch ausschließlich in Handarbeit:</p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir -p web app/cache app/logs app/views app/config  src/Bundle src/Application/HelloBundle/Controller src/Application/HelloBundle/Resources/config src/Application/HelloBundle/Resources/views src/Application/HelloBundle/Resources/views/Hello src/Application/HelloBundle/Entity
</pre>
<p>Anmerkung: Diese wilde Verzeichnisstruktur entspricht 1:1 der Sandbox. Sicherlich steht das endgültige Verzeichnis-Layout eines typischen Symfony2-Projekts noch nicht fest &#8211; auch gibt es ja, wie bereits erwähnt, (noch) keine globale Executable samt symfony:generate-project Task. Ein Ziel von Symfony2 ist, die Modularisierung und Entkopplung der einzelnen Framework-Komponenenten (genannt &#8220;Bundles&#8221;) zu verfeinern. Ähnliche Konzepte kennt man aus der Java-Welt, aber auch bspw. aus CMF wie Silverstripe.</p>
<p>So ist der aktuelle Dev-Branch also eher als lose Sammlung einzelner &#8220;Bundles&#8221; zu verstehen und nicht als Full-Stack-Framework (Die Menge aller Bundles + Task-Bundle wird aber wieder genau das sein). Am ehesten vielleicht vergleichbar mit dem Aufbau des Zend-Frameworks &#8211; wobei das wohl fast als Negativ-Beispiel für &#8220;fake-loose-coupling&#8221; herhalten kann. Symfony2-Bundles sind &#8220;echt&#8221; decoupled und erwarten als einzige Abhängigkeit einen PHP-Autoloader.</p>
<p>&#8220;Bundles&#8221; sind die &#8220;Plugins&#8221; aus Symfony 1.x, mit dem Unterschied, dass das <a href="http://docs.symfony-reloaded.org/guides/internals/overview.html">Core-Framework selbst (&#8220;Kernel&#8221;) wiederum auch ein Bundle ist</a>.</p>
<p>Kurz gesagt: Das Verzeichnislayout, das in Symfony1.x zwar auch mehr oder weniger flexibel war, doch nur unter Schmerzen tiefgreifend veränderlich war, ist nun erstmal völlig variabel. Da ich mich aber an Fabians vorausschauender best-practice orientieren möchte, sieht &#8220;mein&#8221; Verzeichnislayout jetzt eben zufälligerweise aus wie das der Symfony2-Sandbox:</p>
<pre class="brush: bash; title: ; notranslate">
app/
  cache/
  config/
  logs/
  views/
autoload.php.dist
install_vendors.sh
LICENSE
phpunit.xml.dist
README
src/
  Application/
    HelloBundle/
      Controller/
      Entity/
      Resources/
        config/
        views/
  Bundle/
  Symfony/
  vendor/
    ...
tests/
update_vendors.sh
web/
</pre>
<p>Das Verzeichnis /web ist unser Webroot, es sollte nun also ein VirtualHost angelegt werden, der auf dieses zeigt: </p>
<pre class="brush: xml; title: ; notranslate">
&lt;VirtualHost *:80&gt;
  SetEnv APP_ENV dev
  ServerName symfony2.int
  DocumentRoot /var/www/symfony2test/web
&lt;/VirtualHost&gt;
</pre>
<p>Nun können wir damit beginnen, unsere Anwendungsdateien zu erstellen, indem wir einen Frontcontroller anlegen:</p>
<p>web/index.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once __DIR__.'/../app/AppKernel.php';
use SymfonyComponentHttpFoundationRequest;
$kernel = new AppKernel('prod', false);
$kernel-&gt;handle(new Request())-&gt;send();
</pre>
<p>Zunächst holen wir uns den für unsere Anwendung spezifischen Kernel, instanziieren und bitten ihn, einen Http-Request zu bearbeiten.</p>
<p>Damit das Routing funktioniert, benötigen wir noch eine .htaccess-Datei (oder eine entsprechende mod_rewrite-Regel in der VirtualHost-Konfiguration):</p>
<p>web/.htaccess</p>
<pre class="brush: xml; title: ; notranslate">
&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php &#x5B;QSA,L]
&lt;/IfModule&gt;
</pre>
<p>Dann erzeugen wir unseren Kernel und eine Cache-Definition in app/:</p>
<p>app/AppKernel.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once __DIR__.'/../src/autoload.php';

use SymfonyComponentHttpKernelKernel;
use SymfonyComponentDependencyInjectionLoaderLoaderInterface;

class AppKernel extends Kernel
{
    public function registerRootDir()
    {
        return __DIR__;
    }

    public function registerBundles()
    {
        $bundles = array(
            new SymfonyBundleFrameworkBundleFrameworkBundle(),
            new SymfonyBundleTwigBundleTwigBundle(),

            // enable third-party bundles
            new SymfonyBundleZendBundleZendBundle(),
            new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),
            new SymfonyBundleDoctrineBundleDoctrineBundle(),
            
            // register your bundles
            new ApplicationHelloBundleHelloBundle(),
        );

        if ($this-&gt;isDebug()) {
            $bundles&#x5B;] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
        }

        return $bundles;
    }

    public function registerBundleDirs()
    {
        return array(
            'Application'     =&gt; __DIR__.'/../src/Application',
            'Bundle'          =&gt; __DIR__.'/../src/Bundle',
            'Symfony\Bundle' =&gt; __DIR__.'/../src/Symfony/Bundle',
        );
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        // use YAML for configuration
        $loader-&gt;load(__DIR__.'/config/config_'.$this-&gt;getEnvironment().'.yml');
    }
}
</pre>
<p>Interessant sind die beiden zu implementierenden Methoden registerBundles() und registerBundleDirs(). RegisterBundles() teilt dem Kernel mit, welche Bundles in der Anwendung aktiv sind und verwendet werden &#8211; vergleichbar mit enablePlugins() der projectConfiguration.class.php eines beliebigen Symfony 1.x Projekts. registerBundleDirs() mappt wiederum die einzelnen Bundle-Namespaces auf ihre Pfade. Dies ist eigentlich ein wenig doppelt-gemoppelt, verwenden wir doch einen SPL-Autoloader, um unsere Namespaces zu registrieren. Allerdings benötigt der Kernel noch einmal explizit ein Namespace-Bundle-Pfad-Mapping, um bspw. Template-Namespaces korrekt aufzulösen. Stimmt bspw. der Pfad zum SymfonyBundle-Namespace nicht, läuft zwar die Anwendung, doch die Template-Engine kann die Pfade zu bspw. den Assets (Bildern und CSS-Stylesheets) des WebProfilerBundles nicht auflösen. Dies hätte den gleichen Effekt, als hätte ich vergessen, das Assets-Verzeichnis web/sf in einer Symfony 1.x-Anwendung zu referenzieren.</p>
<p>Vorsicht: Die Sandbox und Beispielscripts verwenden hier teils falsche Pfade: So zeigt der Namespace-Pfad der Symfony-Bundles zunächst auf src/vendor/symfony/src/Symfony/Bundle statt auf src/Symfony/Bundle. Das funktioniert in dem Falle auch, weil es eben zwei Symfony-Installationen in der Sandbox gibt (einmal die via install_vendors.sh und die, die man sich selbst gezogen hat). Man sollte sich immerhin für eine entscheiden und seine Projekt- und Arbeitsdateien entsprechend aufräumen. Aber dafür machen wir&#8217;s hier ja auch &#8220;from scratch&#8221;.</p>
<p>Jede Symfony2-Anwendung benötigt zudem eine konkrete, anwendungsspezifische Cache-Implementierung:</p>
<p>app/AppCache.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once __DIR__.'/AppKernel.php';
use SymfonyBundleFrameworkBundleCacheCache;
class AppCache extends Cache
{
}
</pre>
<p>Nun können wir uns an die Konfiguration begeben. In der Datei app/AppKernel.php wird bestimmt, wie und wo konfiguriert wird:</p>
<pre class="brush: php; title: ; notranslate">
    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        // use YAML for configuration
        $loader-&gt;load(__DIR__.'/config/config_'.$this-&gt;getEnvironment().'.yml');
    }
</pre>
<p>Demnach müssen wir für jedes Environment eine config_%env%.yml-Datei erstellen. Dadurch, dass das Symfony2 Configuration-Framework explizite Vererbung (besser: imports) untestützt, reicht eine &#8220;globale&#8221; config.yml und entsprechend angepasste config_%env%.yml-Dateien:</p>
<p>app/config/config.yml</p>
<pre class="brush: python; title: ; notranslate">
app.config:
    charset:       UTF-8
    error_handler: null
    csrf_secret:   xxxxxxxxxx
    router:        { resource: &quot;%kernel.root_dir%/config/routing.yml&quot; }
    validation:    { enabled: true, annotations: true }
    templating:    {} #assets_version: SomeVersionScheme
    session:
        default_locale: en
        lifetime:       3600
        auto_start:     true

# Twig Configuration
twig.config:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%
</pre>
<p>Dann erstellen wir die Konfiguration für das development environment:</p>
<p>app/config/config_dev.yml</p>
<pre class="brush: python; title: ; notranslate">
imports:
    - { resource: config.yml }

app.config:
    router:   { resource: &quot;%kernel.root_dir%/config/routing_dev.yml&quot; }
    profiler: { only_exceptions: false }

webprofiler.config:
    toolbar: true
    intercept_redirects: true

zend.config:
    logger:
        priority: debug
        path:     %kernel.logs_dir%/%kernel.environment%.log
</pre>
<p>In Z. 1 wird config.yml als &#8220;gobale&#8221; Konfiguration importiert. Ansonsten alles mehr oder weniger selbsterklärend, die einzige Auffälligkeit ist, dass das Routing hier nun explizit konfiguriert wird (siehe Z. 5) &#8211; im Gegensatz zu Symfony 1.x-Projekten.</p>
<p>Anmerkung: Falls sich jemand wundern sollte, wo und wie diese Fülle an Optionen dokumentiert sind: Hier hilft nur in die jeweilige <a href="http://components.symfony-project.org/dependency-injection/">Service-Definition des DI-Containers</a> zu schauen. Das mag zu Beginn sehr verwirren, doch die einheitliche Bundle-Struktur hilft da wiederum bei der Navigation. Bundle-Konfigurationen findet man ausschließlich im Verzeichnis Resources/ eines Bundles.</p>
<p>Zurück zur Routing-Configuration, die nun angelegt werden muss:</p>
<p>app/config/routing.yml</p>
<pre class="brush: python; title: ; notranslate">
homepage:
    pattern:  /
    defaults: { _controller: FrameworkBundle:Default:index }

hello:
    resource: HelloBundle/Resources/config/routing.yml
</pre>
<p>app/config/routing_dev.yml</p>
<pre class="brush: python; title: ; notranslate">
_main:
    resource: routing.yml

_profiler:
    resource: WebProfilerBundle/Resources/config/routing/profiler.xml
    prefix:   /_profiler
</pre>
<p>Auch jetzt wurden zwei Routing-Konfigurationen (global und dev), beide werden transparent in config.yml bzw. config_dev.yml referenziert. Die routing_dev.yml ist ausschließlich da um die Route für das WebProfilerBundle zu registrieren.</p>
<p>Die Route &#8220;hello&#8221; in Z. 5 der routing.yml referenziert wiederum eine Bundle-spezifische Route, abzulegen im HelloBundle:</p>
<p>src/Application/HelloBundle/Resources/config/routing.yml:</p>
<pre class="brush: python; title: ; notranslate">
hello:
    pattern:  /hello/:name
    defaults: { _controller: HelloBundle:Hello:index }
</pre>
<p>Somit haben wir fast alles zusammen, um eine Anwendung zum Laufen zu bringen &#8211; Front Controller, Kernel-Konfiguration, Cache, Routing &#8211; nur die konkrete Implementierung unserer Anwendung fehlt noch sowie ein winziges Detail, der Autoloader. Dieser wird ebenfalls durch unseren Kernel angeschmissen (siehe Z. 1 app/AppKernel.php). Erwartet wird eine flache autoload.php-Datei in src/ &#8211; ob sie dort korrekt gelagert ist, oder eher in src/Application liegen sollte oder gar im Projekt root &#8211; das kann sich jeder selbst zusammenreimen.</p>
<p>src/autoload.php:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once __DIR__ . '/Symfony/Component/HttpFoundation/UniversalClassLoader.php';

use SymfonyComponentHttpFoundationUniversalClassLoader;

$vendorDir = __DIR__ . '/vendor';

$loader = new UniversalClassLoader();
$loader-&gt;registerNamespaces(array(
    'Symfony'                        =&gt; __DIR__,
    'Application'                    =&gt; __DIR__,
    'Bundle'                         =&gt; __DIR__,
    'Doctrine\Common\DataFixtures' =&gt; $vendorDir.'/doctrine-data-fixtures/lib',
    'Doctrine\Common'               =&gt; $vendorDir.'/doctrine-common/lib',
    'Doctrine\DBAL\Migrations'     =&gt; $vendorDir.'/doctrine-migrations/lib',
    'Doctrine\ODM\MongoDB'         =&gt; $vendorDir.'/doctrine-mongodb/lib',
    'Doctrine\DBAL'                 =&gt; $vendorDir.'/doctrine-dbal/lib',
    'Doctrine'                       =&gt; $vendorDir.'/doctrine/lib',
    'Zend'                           =&gt; $vendorDir.'/zend/library',
));
$loader-&gt;registerPrefixes(array(
    'Swift_' =&gt; $vendorDir.'/swiftmailer/lib/classes',
    'Twig_'  =&gt; $vendorDir.'/twig/lib',
));
$loader-&gt;register();
</pre>
<p>In autoload.php verwenden wir keine PHP-nativen Autoload-Mechanismen noch den SPL-Autoload-Wrapper direkt, sondern eine weitere Symfony2 Framework-Komponente: Den UniversalClassLoader. Dieser Loader kann Namespaces auflösen, lässt sich aber ebenfalls auf die &#8220;alte&#8221;, unter PHP >= 5.2 gängige Zend bzw. Pear-Notation mappen, was das obige Codesnippet aufzeigt. Intern baut der UniversalClassLoader natürlich auf den entsprechenden SPL-Funktionen auf.</p>
<p>Vorsicht: Der Code entspricht wieder nicht dem originalen Sandbox-Code (Der Namespace-Pfad für die Symfony-Komponenten ist wieder src/ statt src/vendor/symfony/src).</p>
<p>Wir haben weiter oben Routen definiert, die nun entsprechende Endpunkte im HelloBundle brauchen. Wir implementieren dazu eine Bundle-Definition und einen HelloController:</p>
<p>src/Application/HelloBundle/HelloBundle.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace ApplicationHelloBundle;

use SymfonyComponentHttpKernelBundleBundle;

class HelloBundle extends Bundle
{
}

</pre>
<p>src/Application/HelloBundle/Controller:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace ApplicationHelloBundleController;

use SymfonyBundleFrameworkBundleControllerController;

class HelloController extends Controller
{
    public function indexAction($name)
    {
        return $this-&gt;render('HelloBundle:Hello:index.twig', array('name' =&gt; $name));

        // render a PHP template instead
        // return $this-&gt;render('HelloBundle:Hello:index.php', array('name' =&gt; $name));
    }
}
</pre>
<p>und die zugehörige View:</p>
<pre class="brush: xml; title: ; notranslate">
{% extends &quot;HelloBundle::layout.twig&quot; %}

{% block content %}
    Hello {{ name }}!
{% endblock %}
</pre>
<p>Nun müssen wir nur noch die im Template referenzierte Layout-Datei anlegen:</p>
<p>src/Application/HelloBundle/Resources/views/layout.twig:</p>
<pre class="brush: xml; title: ; notranslate">
{% extends &quot;::layout.twig&quot; %}

{% block body %}
    &lt;h1&gt;Hello Application&lt;/h1&gt;

    {% block content %}{% endblock %}
{% endblock %}
</pre>
<p>Und wiederum die in diesem Bundle-spezifischen Layout-Template referenzierte &#8220;globale&#8221; Layout-Datei &#8211; stilsicher mit HTML5-Doctype:</p>
<p>app/views/layout.twig:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
        &lt;title&gt;{% block title %}Hello Application{% endblock %}&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        {% block body %}{% endblock %}
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Das wars. Man sollte nun im Browser zwei Seiten sehen können, einmal die Standard-Projekt-Route &#8220;/&#8221; auf FrameworkBundle:Default:index gemapped und die Route /hello/:name auf HelloBundle:Hello:index gemapped. Zu beachten ist hierbei das Namespace-Mapping auf die Pfade, die im AppKernel unter registerBundleDirs() angegeben wurden &#8211; zum besseren Verständis der Namensraumauflösung der Routen sowie der Templates.</p>
<p>Abschließend kann man sich noch eine Symfony-Konsolenanwendung nach /app legen:</p>
<p>app/console</p>
<pre class="brush: php; title: ; notranslate">
#!/usr/bin/env php
&lt;?php
require_once __DIR__.'/AppKernel.php';
use SymfonyBundleFrameworkBundleConsoleApplication;
$kernel = new AppKernel('dev', true);
$application = new Application($kernel);
$application-&gt;run();
</pre>
<p>nach einem </p>
<pre class="brush: bash; title: ; notranslate">
$ chmod + x app/console
</pre>
<p>kann man nun via ./app/console folgende Ausgabe bewundern und sich mit den ersten Symfony-Bundle-Tasks vertraut machen:</p>
<pre class="brush: bash; title: ; notranslate">
$ app/console
Symfony version 2.0.0-DEV - app

Usage:
  &#x5B;options] command &#x5B;arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this program version.
  --ansi           -a Force ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --shell          -s Launch the shell.

Available commands:
  help                         Displays help for a command (?)
  list                         Lists commands
assets
  :install                     
doctrine
  :ensure-production-settings  Verify that Doctrine is properly configured for a production environment.
doctrine:cache
  :clear-metadata              Clear all metadata cache for a entity manager.
  :clear-query                 Clear all query cache for a entity manager.
  :clear-result                Clear result cache for a entity manager.
doctrine:data
  :load                        Load data fixtures to your database.
doctrine:database
  :create                      Create the configured databases.
  :drop                        Drop the configured databases.
doctrine:generate
  :entities                    Generate entity classes and method stubs from your mapping information.
  :entity                      Generate a new Doctrine entity inside a bundle.
  :proxies                     Generates proxy classes for entity classes.
  :repositories                Generate repository classes from your mapping information.
doctrine:mapping
  :convert                     Convert mapping information between supported formats.
  :convert-d1-schema           Convert a Doctrine 1 schema to Doctrine 2 mapping files.
  :import                      Import mapping information from an existing database.
doctrine:query
  :dql                         Executes arbitrary DQL directly from the command line.
  :sql                         Executes arbitrary SQL directly from the command line.
doctrine:schema
  :create                      Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.
  :drop                        Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.
  :update                      Processes the schema and either update the database schema of EntityManager Storage Connection or generate the SQL output.
init
  :bundle                      
router
  :debug                       Displays current routes for an application
  :dump-apache                 Dumps all routes as Apache rewrite rules

</pre>The post <a href="https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/">Symfony 2 “from scratch” bootstrappen</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2010/12/01/symfony-2-from-scratch-bootstrappen/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
