Symfony 2 application with WordPress as CMS

I would like to build a sf2 application and maintain all the content ( categories, articles, pages, media, etc ) in WordPress with internationalization ( wpml plugin ). The app would have it’s own admin and for managing the content the user would log on to the WordPress backend.

My plan is to have a sf2 controller backed up by the routing system and give it the first chance to identify a route and do its thing. If not it should then let WordPress handle the rendering of the page.

Read More

I also think that I will need to pull WordPress content in some sf2 pages like the homepage where I may want to put the newest articles alongside sf2 content.

Has anyone ever done this before? Pros and cons? Suggestions on how to implement this?
Thanks!

Related posts

Leave a Reply

3 comments

  1. There are some Sf2 bundles that help close the gap a bit, like https://github.com/kayue/KayueWordpressBundle where you can use Symfony2 entities to get WordPress data, authenticate into WordPress, use WordPress functions in Twig, things like that. Maybe you can work with that.

    I did this in a recent project and it worked really well.

    To make this work, you need to have two seperate databases and two entity managers (one for your sf2 application, one for WordPress) – at least that’s how it worked best for me, having a real sf2 application on one side and using WordPress on the side to handle dynamic pages.

    Here is an example of my configuration :

    //app/config.yml
    doctrine:
    dbal:
        default_connection:   default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
            cms:
                driver:   "%database_driver_cms%"
                host:     "%database_host_cms%"
                port:     "%database_port_cms%"
                dbname:   "%database_name_cms%"
                user:     "%database_user_cms%"
                password: "%database_password_cms%"
                charset:  UTF8
    
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        default_entity_manager:   default
        entity_managers:
            default:
                connection:       default
                mappings:
                    MyFirstBundle: ~
                    MySecondBundle: ~ #if you have more than one bundle in your application
            cms:
                connection:       cms
                mappings:
                    KayueWordpressBundle: ~
    

    And the KayueWordpressBundle configuration :

    //app/config.yml
    kayue_wordpress:
    # Site URL must match *EXACTLY* with WordPress's setting. Can be found
    # on the Settings > General screen, there are field named "WordPress Address"
    site_url:       %blog_url% 
    
    #Note : I put the site_url in my parameters.yml to get this working on all my environments (see comment below) 
    
    # Logged in key and salt. Can be found in the wp-config.php file.
    logged_in_key:  'samethingasinyourwpconfig'
    logged_in_salt: 'samethingasinyourwpconfig'
    
    # Optional: WordPress cookie path / domain settings.
    cookie_path:    '/'
    cookie_domain:  null
    
    # Optional: Custom table prefix. Default is "wp_".
    table_prefix:   'wp_'
    
    # Optional: Entity manager configuration to use (cache etc). Default is 'default'.
    entity_manager: 'cms' #here is where i put the name of my new entity manager defined above
    

    Using KayueWordpressBundle, I can now access all elements of my WordPress using the “cms” entity manager. Using WordPress menus, we were able to make our application menu dynamically integrate new pages that were added to them. We were also able to keep the same header and footer on our WordPress using curl, so the whole thing was practically seamless.

    On the practical side :

    I installed WordPress in a file located in the root directory of my project. This means that I can use Git with it, deploy it using Capifony and things like that.

    Note that design, plugins and stuff need to be added/edited on your local environment, then pushed to your Git repository before deploying with Capifony. The dynamic content of your wordpress (pages, articles) however is dependent on your database, so the final content should be written on your production environment only.

  2. First of all, in order to integrate WordPress with Symfony 2, you would have to come up with a “glue” plan, since WordPress doesn’t follow the interoperability standards, followed by Symfony 2 and other frameworks to achieve this level of easy integration.

    Second of all, it would be great if you could check out the Symfony CMF, which is basically an implementation of a content management framework that lets you create your own CMS on top of Symfony 2 components.

    The third and last point would be that this integration that you are trying to achieve doesn’t make a whole lot of sense. The first part of your requirements, where you need a simple layer on top of WordPress to handle the incoming requests, could be solve with a simple hack on WordPress’ front controller code.