有一些 Sf2 捆绑包可以帮助缩小差距,例如https://github.com/kayue/KayueWordpressBundle,您可以在其中使用 Symfony2 实体获取 Wordpress 数据、在 Wordpress 中进行身份验证、在 Twig 中使用 Wordpress 函数等。也许你可以使用它。
我在最近的一个项目中做到了这一点,并且效果非常好。
要完成这项工作,您需要有两个单独的数据库和两个实体管理器(一个用于您的 sf2 应用程序,一个用于 Wordpress) - 至少这对我来说效果最好,一侧有一个真正的 sf2 应用程序并使用 Wordpress处理动态页面的一面。
这是我的配置示例:
//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: ~
KayueWordpressBundle 配置:
//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
使用 KayueWordpressBundle,我现在可以使用“cms”实体管理器访问我的 Wordpress 的所有元素。使用 Wordpress 菜单,我们能够使我们的应用程序菜单动态集成添加到其中的新页面。我们还能够使用 curl 在我们的 Wordpress 上保持相同的页眉和页脚,因此整个事情几乎是无缝的。
在实际方面:
我将 Wordpress 安装在项目根目录中的一个文件中。这意味着我可以使用 Git,使用 Capifony 部署它等等。
请注意,需要在您的本地环境中添加/编辑设计、插件和内容,然后在使用 Capifony 进行部署之前将其推送到您的 Git 存储库。然而,您的 wordpress 的动态内容(页面、文章)取决于您的数据库,因此最终内容应仅在您的生产环境中编写。