Monday, August 12, 2013

Sonata Admin Installation for symfony 2.2

OPTION 1

# composer.json

         "php": ">=5.3.3",
        "symfony/symfony": "2.2.*",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "1.2.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.3.*",
        "symfony/swiftmailer-bundle": "2.2.*",
        "symfony/monolog-bundle": "2.2.*",
        "sensio/distribution-bundle": "2.2.*",
        "sensio/framework-extra-bundle": "2.2.*",
        "sensio/generator-bundle": "2.3.*",
        "jms/security-extra-bundle": "1.4.*",
        "jms/di-extra-bundle": "1.3.*",
        "doctrine/data-fixtures": "*",
        "doctrine/doctrine-fixtures-bundle": "*",
        "friendsofsymfony/user-bundle": "*",
        "knplabs/knp-paginator-bundle": "*",
        "payum/payum-bundle": "*",
        "payum/paypal-express-checkout-nvp": "*",
            "doctrine/doctrine-migrations-bundle": "dev-master",
            "doctrine/migrations": "dev-master",
            "symfony/console": "2.2.*@dev",
            "sonata-project/admin-bundle": "dev-master",
            "sonata-project/doctrine-orm-admin-bundle": "dev-master",
            "sonata-project/intl-bundle": "2.1.*",
            "sonata-project/cache-bundle": "2.*",
            "sonata-project/block-bundle": "2.2.*@dev",
            "simplethings/entity-audit-bundle": "dev-master",
            "knplabs/knp-menu-bundle":"1.1.x-dev"



# app/AutoLoad

# app/AppKernel

            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\AopBundle\JMSAopBundle(),
//            new Acme\HelloBundle\AcmeHelloBundle(),
            new ASF\PembedaBundle\ASFPembedaBundle(),
            new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
//            new Payum\Bundle\PayumBundle\PayumBundle(),
//            new Blogger\BlogBundle\BloggerBlogBundle(),
//            new Doctrine\Bundle\DoctrineMigrationsBundle\DoctrineMigrationsBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
            new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Sonata\jQueryBundle\SonatajQueryBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),

# app/config/config.yml
sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]

        sonata.block.service.text: ~
        sonata.block.service.rss: ~

# app/config/config.yml

install the assets from the bundles: php app/console assets:install web
delete your cache: php app/console cache:clear


 OPTION 2

1. Download Symfony 2.2 package
2. Check version : php app/console -V
3. Install require bundles :
 php composer.phar require sonata-project/block-bundle:2.2.3
 php composer.phar require sonata-project/jquery-bundle:1.8.0 
 php composer.phar require knplabs/knp-menu:1.1.2
 php composer.phar require knplabs/knp-menu-bundle:1.1.2
 php composer.phar require sonata-project/exporter:1.3.0
 php composer.phar require sonata-project/admin-bundle:2.2.2
 php composer.phar require sonata-project/doctrine-orm-admin-bundle:2.2.*@dev
 php composer.phar require sonata-project/intl-bundle:2.1.*
     
4. Alter your config.yml and add following configurations
    # app/config/config.yml
    # Sonata block Configuration
    sonata_block:
        default_contexts: [cms]
        blocks:
            sonata.admin.block.admin_list:
                contexts:   [admin]
            #sonata.admin_doctrine_orm.block.audit:
            #    contexts:   [admin]
            sonata.block.service.text:
            sonata.block.service.rss:
     
     
    # knp menu configuration (optional)
    knp_menu:
        twig:
            template: knp_menu.html.twig
        templating: false
        default_renderer: twig
     
     
    # Translator configuration
    framework:
        translator: ~
     
     
    # Sonata intl configuration
    sonata_intl:
        timezone:
            # default timezone used as fallback
            default: Europe/Paris
     
     
            # locale specific overrides
     
            locales:
                fr: Europe/Paris
                en_UK: Europe/London

5. AppKernel.php
    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\jQueryBundle\SonatajQueryBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\IntlBundle\SonataIntlBundle(),
            // ...
        );
    }
 
6. Install the assets from the bundles 
php app/console assets:install web
 
7.  app/config/routing.yml
     # app/config/routing.yml
    admin:
        resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
        prefix: /admin
     
    _sonata_admin:
        resource: .
        type: sonata_admin
        prefix: /admin
 
 8.  Delete cache files : php app/console cache:clear
 
9. Install FOS & sonata-project/user-bundle
  php composer.phar require friendsofsymfony/user-bundle:1.3.2
  php composer.phar require sonata-project/user-bundle:2.1.1 
  
10 . app/AppKernel.php
 
    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\jQueryBundle\SonatajQueryBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\IntlBundle\SonataIntlBundle(),
     
        new FOS\UserBundle\FOSUserBundle(),
        new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
        new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
            // ...
        );
    }

11. app/config/config.yml

    # app/config/config.yml
    
    # FOS user bundle configuration
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: Application\Sonata\UserBundle\Entity\User

12. Generate & configure User bundle :

php app/console sonata:easy-extends:generate SonataUserBundle
 
add to autoload.php :  $loader->add('Application', __DIR__);
 
        use Doctrine\Common\Annotations\AnnotationRegistry;
        use Composer\Autoload\ClassLoader;
     
        /**
         * @var $loader ClassLoader
         */
        $loader = require __DIR__.'/../vendor/autoload.php';
     
        // intl
        if (!function_exists('intl_get_error_code')) {
            require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
        }
     
        $loader->add('Application', __DIR__);
     
        AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
     
        return $loader; 
 
Register User bundle in app/AppKernel.php : new Application\Sonata\UserBundle\ApplicationSonataUserBundle()
 
// app/AppKernel.php
    public function registerBundles()
    {
        return array(
        // ...
        new Sonata\BlockBundle\SonataBlockBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
        new Sonata\jQueryBundle\SonatajQueryBundle(),
        new Sonata\AdminBundle\SonataAdminBundle(),
        new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        new Sonata\IntlBundle\SonataIntlBundle(),
 
        new FOS\UserBundle\FOSUserBundle(),
        new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
        new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
        new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
        // ...
        );
    }
 
Add fos and sonata user routes in app/routing.yml
 
 #app/routing.yml
    fos_user_security:
       resource: "@FOSUserBundle/Resources/config/routing/security.xml"
    fos_user_profile:
       resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
       prefix: /profile
    fos_user_register:
       resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
       prefix: /register
    fos_user_resetting:
       resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
       prefix: /resetting
    fos_user_change_password:
       resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
       prefix: /change-password
    fos_user_security:
       resource: "@FOSUserBundle/Resources/config/routing/security.xml"
    fos_user_profile:
       resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
       prefix: /profile
    fos_user_register:
       resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
       prefix: /register
    fos_user_resetting:
       resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
       prefix: /resetting
    fos_user_change_password:
       resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
       prefix: /change-password
 
    soanata_user:
       resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
       prefix: /admin
    sonata_user_impersonating:
       pattern: /
       defaults: { _controller: SonataPageBundle:Page:catchAll }
 
clear cache : php app/console cache:clear
 
13. update schema : php app/console doctrine:schema:update --force   
 
 NOTE : if symfony give 'Unknown column type "json" requested.......'  error, add custom type in Doctrine configuration, see below code
    # app/config/config.yml
    doctrine:
        dbal:
        #for SonataNotificationBundle
        types:
            json: Sonata\Doctrine\Types\JsonType
        #----

 14 - Add sonata admin configuration :

    #app/config/config.yml
    sonata_admin:
        title:      <your application title>
        title_logo: /path/to/logo.png
    
        dashboard:
        blocks:
            #          # display a dashboard block
            - { position: left, type: sonata.admin.block.admin_list }


15 - Create super admin user :

php app/console fos:user:create <username> <email> <password>
 
access your admin panel using below url

URL : http://yourdomain/app_dev.php/admin/dashboard 
 
 
 
16 - Bundles url

https://github.com/sonata-project/SonataBlockBundle

https://github.com/sonata-project/SonatajQueryBundle

https://github.com/KnpLabs/KnpMenu

https://github.com/KnpLabs/KnpMenuBundle

https://github.com/sonata-project/exporter

https://github.com/sonata-project/SonataAdminBundle

https://github.com/sonata-project/SonataDoctrineORMAdminBundle

https://github.com/sonata-project/SonataIntlBundle 
 
 
 
 
  Option 3
 
Tested with Symfony Standard 2.0.7 (http://symfony.com/download?v=Symfony_Standard_Vendors_2.0.7.tgz)
This is basically a merge of the installation-guides of FOSUserBundle (https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md), SonataAdminBundle (http://sonata-project.org/bundles/admin/master/doc/reference/installation.html) and SonataUserBundle (http://sonata-project.org/bundles/user/master/doc/reference/installation.html)
  1. Add
    [FOSUserBundle]
        target=bundles/FOS/UserBundle
     
    [SonatajQueryBundle]
        target=/bundles/Sonata/jQueryBundle
     
    [SonataAdminBundle]
        target=/bundles/Sonata/AdminBundle
     
    [MenuBundle]
        target=/bundles/Knp/Bundle/MenuBundle
     
    [KnpMenu]
        target=/knp/menu
     
    [SonataUserBundle]
        target=/bundles/Sonata/UserBundle
     
    [SonataEasyExtendsBundle]
        target=/bundles/Sonata/EasyExtendsBundle
     
    [SonataDoctrineORMAdminBundle]
        target=/bundles/Sonata/DoctrineORMAdminBundle
    to your deps file. (Don’t forget the trailing newline.)
  2. Run
    php bin/vendors install --reinstall
  3. Add the namespaces to app/autoload.php
    // app/autoload.php
    $loader->registerNamespaces(array(
        // ...
        'FOS'              => __DIR__.'/../vendor/bundles',
        'Sonata'           => __DIR__.'/../vendor/bundles',
        'Application'      => __DIR__,
        'Knp'              => array(
                              __DIR__.'/../vendor/bundles',
                              __DIR__.'/../vendor/knp/menu/src',
                              ),
        // ...
    ));
  4. Enable the bundles in app/AppKernel.php
    // app/AppKernel.php
        public function registerBundles()
        {
            $bundles = array(
                // ...
                new FOS\UserBundle\FOSUserBundle(),
                new Sonata\jQueryBundle\SonatajQueryBundle(),
                new Sonata\AdminBundle\SonataAdminBundle(),
                new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
                new Knp\Bundle\MenuBundle\KnpMenuBundle(),
                new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
                new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
                // ...
            );
            // ...
        }
  5. Add
    # app/config/config.yml
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: Application\Sonata\UserBundle\Entity\User
    to app/config/config.yml
  6. Run
    php app/console sonata:easy-extends:generate SonataUserBundle
  7. Add the new Bundle to app/AppKernel.php
    // app/AppKernel.php
        public function registerbundles()
        {
            $bundles = array(
                // Application Bundles
                // ...
                new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
                // ...
            );
            // ...
        }
  8. Add
    # app/config/routing.yml
    fos_user_security:
        resource: "@FOSUserBundle/Resources/config/routing/security.xml"
     
    fos_user_profile:
        resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
        prefix: /profile
     
    fos_user_register:
        resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
        prefix: /register
     
    fos_user_resetting:
        resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
        prefix: /resetting
     
    fos_user_change_password:
        resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
        prefix: /change-password
     
    admin:
        resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
        prefix: /admin
     
    _sonata_admin:
        resource: .
        type: sonata_admin
        prefix: /admin
     
    soanata_user:
        resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
        prefix: /admin
    to app/config/routing.yml
  9. Add the following to app/config/security.yml
    # app/config/security.yml
    security:
        encoders:
            FOS\UserBundle\Model\UserInterface: sha512
     
        role_hierarchy:
            ROLE_ADMIN:       ROLE_USER
            ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
            SONATA:
                - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT  # if you are not using acl then this line must be uncommented
     
        providers:
            fos_userbundle:
                id: fos_user.user_manager
     
        firewalls:
     
            # -> custom firewall for the admin area of the URL
            admin:
                pattern:      /admin(.*)
                form_login:
                    provider:       fos_userbundle
                    login_path:     /admin/login
                    use_forward:    false
                    check_path:     /admin/login_check
                    failure_path:   null
                logout:
                    path:           /admin/logout
                anonymous:    true
            # -> end custom configuration
     
            # defaut login area for standard users
            main:
                pattern:      .*
                form_login:
                    provider:       fos_userbundle
                    login_path:     /login
                    use_forward:    false
                    check_path:     /login_check
                    failure_path:   null
                logout:       true
                anonymous:    true
     
    # ...
     
        access_control:
            # URL of FOSUserBundle which need to be available to anonymous users
            - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
     
            # -> custom access control for the admin area of the URL
            - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin/login-check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            # -> end
     
            - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
     
            # Secured part of the site
            # This config requires being logged for the whole site and having the admin role for the admin part.
            # Change these rules to adapt them to your needs
            - { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
            - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
    # ...
  10. Update your DB-Schema. Run
    php app/console doctrine:schema:update --force
  11. Now, install the assets from the different bundles:
    php app/console assets:install web
  12. Clear your cache:
    php app/console cache:clear
  13. You can create an admin-user and a test-user with the following commands.
    php app/console fos:user:create admin admin@example.com password --super-admin
    php app/console fos:user:create testuser test@example.com password
  14. You need to enable your translator in /app/config.yml.
  15. Create app/Application/Sonata/UserBundle/Recources/translations/SonataUserBundle.en.ymlwith the following content:
    # app/Application/Sonata/UserBundle/Recources/translations/SonataUserBundle.en.yml
    form:
      label_username:             Username
      label_email:                Email
      label_plain_password:       Password (Plain)
      label_groups:               Groups
      label_roles:                Roles
      label_locked:               Locked
      label_expired:              Expired
      label_enabled:              Enabled
      label_credentials_expired:  Credentials Expired
      label_name:                 Name
     
    list:
      label_username:             Username
      label_email:                Email
      label_enabled:              Enabled
      label_locked:               Locked
      label_created_at:           Created At
      label_roles:                Roles
      label_name:                 Name
     
    filter:
      label_username:             Username
      label_locked:               Locked
      label_email:                Email
      label_id:                   ID
      label_name:                 Name
Tags: , , ,

 
 




Thursday, July 18, 2013

Bundle : AlphaLemon

1. AlphaLemon CMS Sandbox
    - Installtion :
        source : https://github.com/alphalemon/AlphaLemonCmsSandbox

      
     Installing from the console
       app/console alphalemon:install-cms
     http://localhost/alcms.php/backend/en/index
         user : admin
         password : admin
  
   Installing using the web interface
     app/console assets:install web
     http://localhost/app_dev.php/install
     http://localhost/alcms.php/backend/en/index
         user : admin
         password : admin
 
   Running test unit :
      phpunit -c app 
     
    

Sunday, July 14, 2013

Installation Symfony 2.3

Installation Symfony 2.3

1. Download at Symfony.com/download link
2. Untar and Copy to www root :
   cd /var/www/symfony
   tar zxvf Symfony_standard.2.x.x.tar.gz
   cp -r Symfony/* /var/www/symfony
   chmod -R 777 app/cache
   chmod -R 777 app/logs
3. Check the pakage & configure
    http://localhosts/web/config.php
    ...
    http://localhosts/web/app_dev.php
 4. or Configure manually
     vi app/config/parameters.yml

Installing vendors
   standard vendor :
   [symfony]
   git=http://github.com/symfony/symfony.git
   version=v2.0.0

   [twig]
   git=http://github.com/fabpot/twig.git
   version=v1.1.1

   [monolog]
   git=http://github.com/Seldaek/monolog.git
   version=1.0.0

   [doctrine]
   git=http://github.com/doctrine/doctrine2.git
   version=2.1.0

   [swiftmailer]
   git=http://github.com/swiftmailer/swiftmailer.git
   version=v4.1.0


Storing new project in github
   git init
   git status
   vi .gitignore
     insert :
        /web/bundles/
        /app/boostrap*
        /app/cache/*
        /app/logs/*
        /vendor/
        /app/config/parameters.ini
        /app/config/parameters.yml
    git add .
    git config --global user.email "kjagro@gmail.com"    git config --global user.email "fadabi"
    git commit -m "Initial commit of the ASF project"
    git add app/config/parameters.yml.dist
    git commit -m "Adding a sample parameter file"

Removing demo pages


Bundles
   FOSUserBundle - user managment
   KnpMenuBundle - really smart menus
   DoctrineFixturesBundle
   StofDoctrineExtensionsBundle - easy doctrine behavior
   AvalancheImagineBundle -  image manipulation
   KnpPaginatorBundle




  









Thursday, June 13, 2013

Steps to move Symfony 2 project to hosting?

Steps to move Symfony 2 project to hosting?

 

Altenative 1

First the httpd.conf file MUST be changed to reference /sites/dir/website/web directory as the DocumentRoot directory, all other files such as lib and config must not be accessible over the web.

 

Altenative 2

 

  1. It depends on kind of hosting that you have: if you have SSH console, then you can do it on hosting after step 2, if you haven`t than do it localy: run command 'php app/console cache:clear --env=prod'.
  2. Suppose you have on you hosting folders youdomain/public_html, so in public_html must be located all web files. So you must upload all from symfony project (folders: app,src,vendors, bin; files: deps, deps.lock), except folder 'web' in folder 'youdomain'. Everuthing from folder 'web' upload to folder public_html.
  3. Check CHMOD for folders app/cache and app/logs, there should be write access.
  4. If there is no file .htaccess in public_html, then create it and add such code in it: https://raw.github.com/symfony/symfony-standard/master/web/.htaccess
  5. Now you should use youdomain.com/index instead of youdomain.com/app_dev.php/index, that you use locally. If site still did not works, you can open file web/config.php and find code where perform check for IP, you find there only ip 127.0.0.1, add your current ip to this list and upload new config on server. Then you can open path yourdomain/config.php and check what`s wrong. If config.php shows that everything ok, but still didn't work, you can enable app_dev.php to debug: open app/app_dev.php and your ip as for config.php. Now you can run scripts as localy using app_dev.php.

 

 

Alternative3

 

I got it to work, this is my experience:
  • Upload the whole project folder to the server.
  • Enter www.your-website.com/project-name/web/config.php.
  • It should say: "This script is only accessible from localhost".
  • Open this web site: http://www.whatismyip.com, it should show you your public IP address, copy it.
  • Open the config.php from the admin panel (like cPanel) and edit that config.php:

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', /*your IP here*/))) {
    header('HTTP/1.0 403 Forbidden');
    die('This script is only accessible from localhost.');  
}

  • Refresh your config.php file, the page will tell you if your system is missing some required conditions like: PHP version, APC extension, giving /cache and /log folders permissions to write on, etc.
  • After you provide the required conditions you'll see a form of configuring you project to connect to a database if you have one, this step is pretty simple.
  • Open the link www.your-website.com/project-name/web/app_dev.php, it'll help you get started with Symfony2 project.
  • In case you got in app_dev.php this message: You are not allowed to access this file... just do the same thing to app_dev.php as you did in steps 4 and 5 (add your public IP address to the array).
    Note of Hakan Deryal (comment): If you don't have a fix IP address, you need to do this last step each time you get a new IP adrdress from the DHCP. So to solve that, open the app_dev.php and comment out the line die('You are not allowed to.., however this is not a recommended way because you're disabling the built-in security of the file.
  • One thing stopped me and may stop you too, the server I deployed the project on, was case-sensitive (unlike the localhost on my computer), so it kept telling me that the template (Index.html.php for example) does not exist, however it does exist, but I did return $this->render('...:index.html.php') with small i in DefaultController.php. So render the exact template (file) name with the same letters cases.
Now everything is going well, I hope that helps you.

 

Thursday, June 6, 2013

Paginator Bundle :: KnpPaginatorBundle

1. Installation
    -add to composer.json

{
    "require": {
        "knplabs/knp-paginator-bundle": "dev-master"
    }
}
 
 
2. configure
  - add app/config/config.yml
 
knp_paginator:
    page_range: 5                      # default page range used in pagination control
    default_options:
        page_name: page                # page query parameter name
        sort_field_name: sort          # sort field query parameter name
        sort_direction_name: direction # sort direction query parameter name
        distinct: true                 # ensure distinct results, useful when ORM queries are using GROUP BY statements
    template:
        pagination: KnpPaginatorBundle:Pagination:sliding.html.twig     # sliding pagination controls template
        sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
 
 
  3. Add to application kernel
   - add  app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
        // ...
    );
} 
 
 
 
 
 
The controller :
 
 
        $em    = $this->get('doctrine.orm.entity_manager');
        $dql   = "SELECT a FROM ASFPembedaBundle:Quran a WHERE a.sura = '$surah'";
        $query = $em->createQuery($dql);

        $paginator  = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
           $query,
           $this->get('request')->query->get('page', 1)/*page number*/,
           10/*limit per page*/
        );


        return $this->render('ASFPembedaBundle:Quran:qsurah.html.twig', array(
            'pagination' => $pagination,
            'comments'  => 'ssssss'
        ));
 
 
The view :
 
   <table border=1>
   {# table body #}
   {% for ayat in pagination %}
         <tr {% if loop.index is odd %}class="snippet"{% endif %}>
            <td>{{ ayat.aya }}</td><td>{{ ayat.text }}</td>
         </tr>
         <tr {% if loop.index is odd %}class="grey"{% endif %}>
            <td></td><td>
            <div>
               <p>{{ ayat.quranmakna.mtext }}</p>
            </div>
            </td>
         </tr>
         
    {% else %}
        <p>Search text not found</p>
    {% endfor %}
</table>
   
{# display navigation #}
<div class="navigation">
    {{ knp_pagination_render(pagination) }}
</div> 
 

Unknown database type enum requested ...

Installing the FOSuser and get error after the below step command :

php app/console doctrine:schema:update --force


[Doctrine\DBAL\DBALException]                                               
  Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform 
   may not support it.


doctrine:schema:update [--complete] [--dump-sql] [--force] [--em[="..."]]


vi app/config/config.app

add :

mapping_types:
    enum: string
 
 
to the doctrine:dbal:
 
like this : 
 
 
doctrine:
    dbal:
        driver: %database_driver%
         host: %database_host%
         port: %database_port%
         dbname: %database_name%
         user: %database_user%
         password: %database_password%
         charset: UTF8
         mapping_types:
             enum: string 

Wednesday, June 5, 2013

Login Bundle :: FOSUser

ref : https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md#LNaN

Install login bundle :

Step 1:  edit composer.json

{
    "require": {
        "friendsofsymfony/user-bundle": "~2.0@dev"
    }
}

Step 2:  download
php composer.phar update friendsofsymfony/user-bundle
 

Step 3:  Enable bundle, edit app/AppKernel.php
 
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\UserBundle\FOSUserBundle(),
    );
}
 
  
Step 4:  Creating User Class

<?php 
// src/ASF/PembedaBundle/Entity/User.php

namespace ASF\PembedaBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}
 
 
Step 5: Configure your application's security.yml
 
 
# app/config/security.yml
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN } 
 
 
Step 6: Configure the FOSUserBundle
 
 # app/config/config.yml
fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: ASF\PembedaBundle\Entity\User
 
Step 7: Import FOSUserBundle routing files



# app/config/routing.yml
fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile


Step 8: Update your database schema


php app/console doctrine:schema:update --force
 
You now can login at http://symfony/app_dev.php/login