Pierwsze kroki – Stworzenie projektu i frontendu

Symfony, originally uploaded by Pierre Nel.

Zrobiłem pierwsze kroki z Symfony i trochę przeraża mnie wielkość tego frameworka. Ale cóż, damy radę. Najbardziej przerażający jest istny burdel w dokumentacji, nic tam nie widzę, muszę wertować miliony stron, żeby coś znaleźć.

Tworzę swoją pierwszą aplikacje w Symfony i mam nadzieję, że wszystko będzie ok. Na początku dowiedziałem się jak utworzyć projekt w Symfony i FrontEnd do niego. Irytuje mnie backspace w WordPressie. Niestety użyłem jako ORM Propela, a nie Doctrine – Doctrine jest szybsze, lepsze.

cd /var/www
mkdir sfdemo
cd sfdemo
symfony

Po wykonaniu polecenia symfony wyświetla nam listę dostępnych funkcji etc.

sokol@sokol-desktop:~$ symfony
Usage:
symfony [options] task_name [arguments]

Options:
–dry-run     -n  Do a dry run without executing actions.
–help        -H  Display this help message.
–quiet       -q  Do not log messages to standard output.
–trace       -t  Turn on invoke/execute tracing, enable full backtrace.
–version     -V  Display the program version.

Available tasks:
:help                       Displays help for a task (h)
:list                       Lists tasks
app
:routes                     Displays current routes for an application
cache
:clear                      Clears the cache (cc, clear-cache)
configure
:author                     Configure project author
:database                   Configure database DSN
generate
:app                        Generates a new application (init-app)
:module                     Generates a new module (init-module)
:project                    Generates a new project (init-project)
:task                       Creates a skeleton class for a new task
i18n
:extract                    Extracts i18n strings from php files
:find                       Finds non “i18n ready” strings in an application
log
:clear                      Clears log files (log-purge)
:rotate                     Rotates an application log files (log-rotate)
plugin
:add-channel                Add a new PEAR channel
:install                    Installs a plugin (plugin-install)
:list                       Lists installed plugins (plugin-list)
:publish-assets             Publishes web assets for all plugins
:uninstall                  Uninstalls a plugin (plugin-uninstall)
:upgrade                    Upgrades a plugin (plugin-upgrade)
project
:clear-controllers          Clears all non production environment controllers (clear-controllers)
:deploy                     Deploys a project to another server (sync)
:disable                    Disables an application in a given environment (disable)
:enable                     Enables an application in a given environment (enable)
:freeze                     Freezes symfony libraries (freeze)
:permissions                Fixes symfony directory permissions (permissions, fix-perms)
:unfreeze                   Unfreezes symfony libraries (unfreeze)
:upgrade1.1                 Upgrade a symfony project to the 1.1 symfony release
:upgrade1.2                 Upgrade a symfony project to the 1.2 symfony release (from 1.1)
propel
:build-all                  Generates Propel model and form classes, SQL and initializes the database (propel-build-all)
:build-all-load             Generates Propel model and form classes, SQL, initializes the database, and loads data (propel-build-all-load)
:build-filters              Creates filter form classes for the current model
:build-forms                Creates form classes for the current model
:build-model                Creates classes for the current model (propel-build-model)
:build-schema               Creates a schema from an existing database (propel-build-schema)
:build-sql                  Creates SQL for the current model (propel-build-sql)
:data-dump                  Dumps data to the fixtures directory (propel-dump-data)
:data-load                  Loads data from fixtures directory (propel-load-data)
:generate-admin             Generates a Propel admin module
:generate-module            Generates a Propel module (propel-generate-crud, propel:generate-crud)
:generate-module-for-route  Generates a Propel module for a route definition
:graphviz                   Generates a graphviz chart of current object model
:init-admin                 Initializes a Propel admin module (propel-init-admin)
:insert-sql                 Inserts SQL for current model (propel-insert-sql)
:schema-to-xml              Creates schema.xml from schema.yml (propel-convert-yml-schema)
:schema-to-yml              Creates schema.yml from schema.xml (propel-convert-xml-schema)
test
:all                        Launches all tests (test-all)
:coverage                   Outputs test code coverage
:functional                 Launches functional tests (test-functional)
:unit                       Launches unit tests (test-unit)

Niech to tutaj zostanie.

Stworzenie szkieletu projektu i frontendu jest banalnie proste. Wystarczy wpisać jedną komendę. sfdemo to nazwa projektu.

symfony generate:project sfdemo

Projekt już jest stworzony.

Symfony teraz groźnie wyświetlił mi co zrobił – dir+ prawdopodobnie oznacza utworzenie katalogu, a file+ pliku. chmod 777 zapewne oznacza zmianę uprawnień do poszczególnych plików/folderów.

>> dir+      /var/www/sfdemo/web
>> file+     /var/www/sfdemo/web/robots.txt
>> dir+      /var/www/sfdemo/web/js
>> dir+      /var/www/sfdemo/web/images
>> file+     /var/www/sfdemo/web/.htaccess
>> dir+      /var/www/sfdemo/web/uploads
>> dir+      /var/www/sfdemo/web/uploads/assets
>> dir+      /var/www/sfdemo/web/css
>> file+     /var/www/sfdemo/web/css/main.css
>> dir+      /var/www/sfdemo/log
>> dir+      /var/www/sfdemo/config
>> file+     /var/www/sfdemo/config/ProjectConfiguration.class.php
>> file+     /var/www/sfdemo/config/rsync_exclude.txt
>> file+     /var/www/sfdemo/config/vhost.sample
>> file+     /var/www/sfdemo/config/databases.yml
>> file+     /var/www/sfdemo/config/propel.ini
>> file+     /var/www/sfdemo/config/schema.yml
>> file+     /var/www/sfdemo/config/properties.ini
>> dir+      /var/www/sfdemo/test
>> dir+      /var/www/sfdemo/test/unit
>> dir+      /var/www/sfdemo/test/functional
>> dir+      /var/www/sfdemo/test/bootstrap
>> file+     /var/www/sfdemo/test/bootstrap/functional.php
>> file+     /var/www/sfdemo/test/bootstrap/unit.php
>> dir+      /var/www/sfdemo/lib
>> dir+      /var/www/sfdemo/cache
>> file+     /var/www/sfdemo/symfony
>> dir+      /var/www/sfdemo/apps
>> dir+      /var/www/sfdemo/doc
>> dir+      /var/www/sfdemo/plugins
>> dir+      /var/www/sfdemo/data
>> dir+      /var/www/sfdemo/data/fixtures
>> file+     /var/www/sfdemo/data/fixtures/fixtures.yml
>> tokens    /var/www/sfdemo/config/databases.yml
>> tokens    /var/www/sfdemo/config/propel.ini
>> tokens    /var/www/sfdemo/config/properties.ini
>> tokens    /var/www/sfdemo/config/ProjectConfiguration.class.php
>> tokens    /var/www/sfdemo/config/vhost.sample
>> chmod 777 /var/www/sfdemo/web/uploads
>> chmod 777 /var/www/sfdemo/cache
>> chmod 777 /var/www/sfdemo/log
>> chmod 777 /var/www/sfdemo/symfony
>> chmod 777 /var/www/sfdemo/web/uploads/assets
>> plugin    Configuring plugin – sfPropelPlugin
>> plugin    Configuring plugin – sfProtoculousPlugin

Teraz powinniśmy wygenerować tak zwany Frontend aplikacji. Aby to zrobić wystarczy wpisać jedną komendę. PS. Nie wszystko w Symfony robi się jedną komendą…

symfony generate:app frontend

//Wynik:

>> dir+      /var/www/sfdemo/apps/frontend/config
>> file+     /var/www/sfdemo/apps/frontend/config/filters.yml
>> file+     /var/www/sfdemo/apps/frontend/config/security.yml
>> file+     /var/www/sfdemo/apps/frontend/config/cache.yml
>> file+     /var/www/sfdemo/apps/frontend/config/app.yml
>> file+     /var/www/sfdemo/apps/frontend/config/routing.yml
>> file+     /var/www/sfdemo/apps/frontend/c…licationConfiguration.class.php
>> file+     /var/www/sfdemo/apps/frontend/config/view.yml
>> file+     /var/www/sfdemo/apps/frontend/config/factories.yml
>> file+     /var/www/sfdemo/apps/frontend/config/settings.yml
>> dir+      /var/www/sfdemo/apps/frontend/templates
>> file+     /var/www/sfdemo/apps/frontend/templates/layout.php
>> dir+      /var/www/sfdemo/apps/frontend/modules
>> dir+      /var/www/sfdemo/apps/frontend/lib
>> file+     /var/www/sfdemo/apps/frontend/lib/myUser.class.php
>> dir+      /var/www/sfdemo/apps/frontend/i18n
>> tokens    /var/www/sfdemo/apps/frontend/config/settings.yml
>> file+     /var/www/sfdemo/web/index.php
>> file+     /var/www/sfdemo/web/frontend_dev.php
>> tokens    /var/www/sfdemo/web/index.php
>> tokens    /var/www/sfdemo/web/frontend_dev.php
>> rename    /var/www/sfdemo/apps/frontend/c…frontendConfiguration.class.php
>> tokens    /var/www/sfdemo/apps/frontend/c…frontendConfiguration.class.php
>> chmod 777 /var/www/sfdemo/web/uploads
>> chmod 777 /var/www/sfdemo/cache
>> chmod 777 /var/www/sfdemo/log
>> chmod 777 /var/www/sfdemo/symfony
>> chmod 666 /var/www/sfdemo/cache/project_autoload.cache
>> chmod 777 /var/www/sfdemo/web/uploads/assets
>> dir+      /var/www/sfdemo/test/functional/frontend

Aby zobaczyć stworzoną przez generatory stronę wystarczy wejść pod ten adres http://localhost/sfdemo/web/frontend_dev.php. Niestety jak sam pewnie zauważyłeś ten adres nie jest dość prosty i większość rzeczy nie działa. Nie ma kaskadowych arkuszy stylów, grafik innych pierdół.

Konfiguracja Apache2

Podręcznik Symfony radzi, aby rozwiązać ten problem edytując plik apache2 z hostami. U mnie /etc/apache2/sites-enabled/ używam Ubuntu 9.04 nie wiem jaka lokalizacja jest u Ciebie w Debianie na pewno jest podobna.

W miejsca oznaczone $sf_symfony_data_dir wpisz dokładną ścieżkę do folderu, w którym zostało zainstalowane symfony. W moim wypadku jest to /usr/share/php/data/symfony .

W miejsca opisane jako /home/steve/myproject/web wpisz ścieżkę do folderu web w naszym projekcie, w moim wypadku /var/www/sfdemo/web

<VirtualHost *:80>
  ServerName myapp.example.com
  DocumentRoot "/home/steve/myproject/web"
  DirectoryIndex index.php
  Alias /sf /$sf_symfony_data_dir/web/sf
  <Directory "/$sf_symfony_data_dir/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
  <Directory "/home/steve/myproject/web">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Restartujemy Apache, u mnie /etc/init.d/apache2 restart - nie wiem jak u Ciebie. Jeżeli coś nie działa to wróć do nagłówka “Konfiguracja Apache2″ i przeczytaj go dokładnie, a nie przeklejaj kod.

Podsumowanie

Do tej pory utworzyliśmy projekt, frondend do niego oraz skonfigurowaliśmy apache2 tak, aby wyświetlał naszą witrynę poprawnie. Na razie to wszystko.

Dodaj komentarz

Filed under Symfony

Dodaj komentarz

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Zmień )

Twitter picture

You are commenting using your Twitter account. Log Out / Zmień )

Facebook photo

You are commenting using your Facebook account. Log Out / Zmień )

Connecting to %s