survos / landing-bundle
为 Symfony5 应用程序添加一些工具和资源
Requires
- ext-json: *
- ext-zip: *
- knplabs/knp-menu: ^3.0
- knplabs/knp-menu-bundle: ^3.0@dev
- knpuniversity/oauth2-client-bundle: ^1.0
- meyfa/php-svg: ^0.9.1
- symfony/mailer: *
- symfony/orm-pack: *
- symfony/webpack-encore-bundle: ^1.6|^2
- symfony/yaml: *
- twig/twig: ^2.5|^3.0
Requires (Dev)
README
@todo
添加新的 Bundle 目录约定,与标准骨架保持一致
└── MyBundle/
├── config/
├── public/
├── src/
│ └── MyBundle.php
├── templates/
└── translations/
class MyBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
一个有适度偏见的 Bundle,提供了一种快速使用最佳实践来启动和运行 Symfony 的方法。
除了 Symfony 网络骨架之外,此 Bundle 还需要
- JavaScript: jquery, bootstrap
- Symfony: KnpMenu, WebpackEncore
并推荐
- JavaScript: fontawesome
- Symfony: EasyAdminBundle
目标
此 Bundle 最初创建是为了隔离其他 Bundle 的问题,并尽可能快速、痛苦地获取网站上的数据。
要求
- composer
- PHP 7.1+
- yarn
- Symfony CLI(用于运行本地服务器、创建项目等)
创建 github 项目
-
创建一个新的存储库
在 github.com 上创建一个没有文件(没有 README 或许可证)的存储库,将其克隆到某个目录并转到那里。
REPO=xml-serializer-demo && git clone git@github.com:tacman/$REPO.git && cd $REPO
-
创建 Symfony 骨架时不使用 git 仓库,然后添加该仓库。
mv .git .. && symfony new --full . --no-git && mv ../.git .
登录后,在 heroku 上创建项目
heroku create $REPO
bin/console make:user User --is-entity --identity-property-name=email --with-password -n
# composer config extra.symfony.allow-contrib true
# interaction is required for the next commands, so if you're cutting and pasting, stop here!
# use the defaults (App\Entity\User)
创建 LoginFormAuthenticator
bin/console make:auth 1 # Login Form Authenticator AppAuthenticator <return> # SecurityController <return> # /logout
# Optional, since SurvosBaseBundle has this already, formatted for mobile
bin/console make:registration-form
# Now install the Landing (SurvosBase?) bundle
composer config minimum-stability dev
composer req survos/landing-bundle
composer config repositories.adminlte '{"type": "vcs", "url": "git@github.com:tacman/AdminLTEBundle.git"}'
composer config repositories.blog '{"type": "vcs", "url": "git@github.com:survos/OdiseoBlogBundle.git"}'
# local dev: create a symlink
composer config repositories.survoslanding '{"type": "path", "url": "../Survos/LandingBundle"}'
composer config repositories.geonames '{"type": "path", "url": "../Survos/geonames-bundle"}'
composer config repositories.phpspreadsheet '{"type": "path", "url": "../Survos/phpspreadsheet-bundle"}'
composer config repositories.multisearch '{"type": "vcs", "url": "git@github.com:tacman/PetkoparaMultiSearchBundle.git"}'
composer config repositories.captcha '{"type": "vcs", "url": "git@github.com:cyrilverloop/symfony-captcha-bundle.git"}'
composer config repositories.git-survoslanding '{"type": "vcs", "url": "https://github.com/survos/LandingBundle.git"}'
composer config repositories.git-geonames '{"type": "vcs", "url": "https://github.com/survos/geonames-bundle.git"}'
composer config repositories.flowdemo '{"type": "path", "url": "../Survos/../CraueFormFlowDemoBundle"}'
composer config repositories.social_post_bundle '{"type": "path", "url": "../Survos/social-post-bundle"}'
composer config repositories.social_post_bundle '{"type": "vcs", "url": "https://github.com/tacman/social-post-bundle"}'
# this is needed because it creates MAILER_DSN, which isn't created otherwise
# composer req mail
composer req knplabs/knp-menu-bundle:"^3.0@dev"
composer req survos/landing-bundle:"*@dev"
phpstorm .env
或者
composer req survos/landing-bundle
# creates survos_landing.yaml (a recipe would be nicer!)
bin/console survos:init
# edit .env and set MAILER_URL
糟糕,仍然不起作用,需要着陆菜单
# introspection, creates menus, looks for entities, easyadmin, etc.
bin/console survos:configure
# symfony run -d yarn encore dev --watch
集成 Facebook 和其他 OAuth
转到 https://github.com/knpuniversity/oauth2-client-bundle#step-1-download-the-client-library
例如。
composer require league/oauth2-facebook
创建应用程序并启用登录: https://developers.facebook.com/apps/
需要一个配置脚本,询问 ID 并将其设置在 .env.local(或 Heroku 等)中
https://developers.facebook.com/apps/558324821626788/settings/basic/
安装和配置 UserBundle(可选)
参见 [docs/recommended_bundles]
如果开发 LandingBundle
composer config repositories.survoslanding '{"type": "path", "url": "../Survos/LandingBundle"}'
composer req survos/landing-bundle:"*@dev"
常规安装
安装 Bundle,然后通过设置过程添加和配置工具。
composer req survos/landing-bundle
yarn install
xterm -e "yarn run encore dev-server" &
composer req "kevinpapst/adminlte-bundle"
bin/console make:subscriber KnpMenuSubscriber "KevinPapst\AdminLTEBundle\Event\KnpMenuEvent"
bin/console survos:init
bin/console survos:config --no-interaction
bin/console doctrine:schema:update --force
survos:init
首次设置,下载 jquery、bootstrap 等。还会 修改 一些 yaml 文件,并创建第一个菜单。
# config/packages/admin_lte.yaml admin_lte: knp_menu: enable: true routes: adminlte_welcome: app_homepage adminlte_login: app_login adminlte_profile: app_profile
@todo: 生成此控制器和模板?
# config/routes/survos_landing.yaml survos_landing: {path: /, controller: 'Survos\LandingBundle\Controller\LandingController::landing'} # app_homepage: {path: /, controller: 'Survos\LandingBundle\Controller\LandingController::landing'} app_logo: {path: /logo, controller: 'Survos\LandingBundle\Controller\LandingController::logo'} app_profile: {path: /profile, controller: 'Survos\LandingBundle\Controller\LandingController::profile'} # profile: {path: /profile, controller: 'Survos\LandingBundle\Controller\LandingController::profile'} # logout: {path: /logout, controller: 'Survos\LandingBundle\Controller\LandingController::logout'} # required if app_profile is used, since you can change the password from the profile app_change_password: {path: /change-password, controller: 'Survos\LandingBundle\Controller\LandingController::changePassword'}
{% extends '@AdminLTE/layout/default-layout.html.twig' %} {% block page_content %} {{ block('body') }} {% endblock %}
{% block logo_mini %}KPA{% endblock %} {% block logo_large 'KPA Admin' %}
{% block page_title 'KPA Admin' %} {% block page_subtitle '歌曲和音乐!' %}
现在安装一些 Bundle!
See the details at [Recommended Bundles](docs/recommended-bundles.md)
如果您选择集成用户 Bundle,则更新模式并添加一个管理员
bin/console doctrine:schema:update --force
symfony server:start --no-tls
完成之后,应用程序将有一个基本的着陆页面,包括顶部导航,可选地包含登录/注册页面。已登录用户(可选地)还将(可选地)有访问 easyadmin 和 api-platform 的链接。
Api Platform
@todo: 将此放入 survos:setup 命令。
- 公开 API 路由(用于 jsRoutingBundle),并
# config/routes/api_platform.yaml api_platform: resource: . type: api_platform prefix: /api options: expose: true
创建 resources.yaml 以存储配置
# api/config/api_platform/resources.yaml App\Entity\User: ~ App\Entity\Location: shortName: 'Location' # optional description: 'A place within a building where inventory item is physically located.' # optional attributes: # optional pagination_items_per_page: 30 # optional normalization_context: groups: ['jstree'] denormalization_context: groups: ['jstree']
将 resources.yaml 目录添加到映射路径中
# config/packages/api_platform.yaml api_platform: mapping: paths: - '%kernel.project_dir%/src/Entity' - '%kernel.project_dir%/config/api_platform' # yaml or xml directory configuration] patch_formats: json: ['application/merge-patch+json'] swagger: versions: [3]
配置序列化器(可能需要创建目录)
# config/serializer/serialization.yaml App\Entity\User: attributes: id: groups: ['Default'] email: groups: ['Default'] App\Entity\Song: attributes: title: groups: ['Default']
自定义 Bundle
部署到 heroku
heroku create $projectName
echo "web: vendor/bin/heroku-php-nginx -C heroku-nginx.conf -F fpm_custom.conf public/" > Procfile
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add --index 2 heroku/nodejs
composer config --unset repositories.survoslanding && composer update
git commit -m "unset survoslanding" . && git push heroku master
https://devcenter.heroku.com/articles/deploying-symfony4 bin/console survos:setup-heroku