ホームページ >バックエンド開発 >PHPチュートリアル >Fosuserbundleを使用したSymfony2の基本的なユーザー管理
このチュートリアルでは、Fosuserbundleをユーザー認証と管理のためのSymfonyプロジェクトに統合する方法を示しています。 Fosuserbundleは、ユーザーの登録、ログイン、パスワードリセット、プロファイル管理を簡素化し、Symfonyのセキュリティシステムを活用します。
fosuserbundleの重要な機能:Symfonyのセキュリティシステムに基づいて構築されています
は、教義や推進のようなmongodbとormを支持します。このガイドでは、Homesteadが改善されています。 新しいサイトをファイルに追加します:
ファイルに追加します。 VMを。で起動します
これらのコマンドを使用して、およびこれらのコマンドを使用してVM内にSymfonyインストーラーをインストールします。
Homestead.yml
<code class="language-yaml">sites: - map: symfonylogin.app to: /home/vagrant/Code/SymfonyLogin/web type: symfony databases: - symfony</code>
192.168.10.10 symfonylogin.app
データベースと電子メールの設定で/etc/hosts
を構成します。 vagrant up
でスケルトンアプリケーションにアクセスします。
を調整する必要がある場合があります。
vagrant ssh
<code class="language-bash">curl -LsS http://symfony.com/installer > symfony sudo mv symfony /usr/local/bin/symfony chmod a+x /usr/local/bin/symfony</code>
<code class="language-bash">cd Code symfony new SymfonyLogin</code>
parameters.yml
インストール:http://symfonylogin.app
コンポーザーの使用:
app_dev.php
バンドル登録:in
、
<code class="language-bash">composer require friendsofsymfony/user-bundle "~2.0@dev"</code>構成(
翻訳者を有効にします:
AppKernel.php
new FOSUserBundleFOSUserBundle()
$bundles
:
config.yml
ユーザーエンティティ(
<code class="language-yaml">translator: { fallbacks: ["%locale%"] }</code>:
:security.yml
を拡張するユーザーエンティティを作成します
<code class="language-yaml">security: encoders: AppBundle\Entity\User: bcrypt # ... (rest of security configuration)</code>
<code class="language-yaml">fos_user: db_driver: orm firewall_name: main user_class: AppBundle\Entity\User from_email: address: admin@example.com sender_name: Example.com registration: confirmation: enabled: true template: FOSUserBundle:Registration:email.txt.twig</code>データベーススキーマを更新:
src/AppBundle/Entity/User.php
FOSUserBundleModelUser
ルートをインポートする(
<code class="language-php"><?php // ... (Entity code as in original example) ?></code>
(画像:デフォルト登録フォーム)
<code class="language-bash">php app/console doctrine:schema:update --force</code>
routing.yml
テンプレートのカスタマイズ:
<code class="language-yaml">fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml"</code>
app/Resources/FOSUserBundle/views/Registration/
を作成し、vendor/friendsofsymfony/user-bundle/Resources/views/Registration/
から必要なテンプレートをコピーします。これらのテンプレートを変更して、登録フォームの外観をカスタマイズします。 例の変更は、元の例に示されています。
register.html.twig
register_content.html.twig
(画像:カスタマイズされた登録フォーム)
さらなるカスタマイズ:
翻訳:
。app/Resources/translations/
以上がFosuserbundleを使用したSymfony2の基本的なユーザー管理の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。