goutte / wordpress-bundle
该软件包的最新版本(v0.1)没有可用的许可证信息。
v0.1
2012-11-19 12:09 UTC
Requires
- php: >=5.3.3
- doctrine/data-fixtures: dev-master
- stof/doctrine-extensions-bundle: dev-master
This package is not auto-updated.
Last update: 2024-09-28 14:06:57 UTC
README
这是一个WordPress和Symfony2之间的桥梁。
此包将允许您
- 找到已发布的文章/页面
- 所有这些
- 通过slug查找
- 通过MIME类型查找附件,特别是图片
这就是全部!
受到(很多!)以下的影响
- https://github.com/kayue/WordpressBundle
- 及其活跃的分支 https://github.com/101medialab/WordpressBundle
- https://github.com/PolishSymfonyCommunity/PSSBlogBundle
我完全重写了这个包,因为我想要在所有时候都有工作且干净的测试。此外,它是一个学习项目。
您不应该使用此包,因为同时使用WordPress和Symfony2是不良实践,但直到CMF准备就绪,这在一些快餐案例中仍然是一个足够好的替代品。
如何使用
-
像往常一样创建您的WordPress
-
将 此包 添加到您的composer.json中
-
在您的AppKernel.php中注册此包
-
在app/config.yml中进行配置
goutte_wordpress: # WP tables prefix, default is 'wp_' table_prefix: wp_
-
在parameters.yml中配置您的参数,使其指向WordPress数据库
使用示例
您需要实体管理器
$em = $this->get('doctrine')->getEntityManager(); // whichever way you're using to get the em
文章
将仅获取文章,而不是页面或附件。(以下是如何获取这些内容的方法)
$postRepository = $em->getRepository('GoutteWordpressBundle:Post'); $posts = $postRepository->findPublished(); // finds all published posts // finds a maximum of 5 published posts after omitting the first 3 $posts = $postRepository->findPublished(5,3); // finds one post by its slug, or returns false $post = $postRepository->findPublishedBySlug('hello-word');
页面
$pageRepository = $em->getRepository('GoutteWordpressBundle:Page'); $pages = $pageRepository->findPublished(); // finds all published pages // finds a maximum of 5 published pages after omitting the first 3 $pages = $pageRepository->findPublished(5,3); // finds one page by its slug, or returns false $page = $pageRepository->findPublishedBySlug('hello-word');
图片
<?php $attachmentRepository = $em->getRepository('GoutteWordpressBundle:Attachment') // Find all images (attachments whose mime-type starts with 'image/') $allImages = $attachmentRepository->findImages(); // any mime subtype works as parameter, juste make sure to spell it as wordpress does (eg: jpeg vs jpg) $pngImages = $attachmentRepository->findImages('png'); $jpgImages = $attachmentRepository->findImages('jpeg'); // you can also pass an array, for convenience $transparentImages = $attachmentRepository->findImages(array('gif','png', 'webp'));
附件
// you may also use directly the query builder, for flexibility $documentsQb = $attachmentRepository->cqbForTypeAndSubtypes('application', array('pdf','msword')); $documentsQb = $documentsQb->orderBy('a.comment_count', 'DESC'); // see BasePost Entity for field name $documents = $documentsQb->getQuery->getResult();
如何设置测试
-
将phpunit.xml.dist复制到phpunit.xml
-
配置KERNEL_DIR
-
在您的AppKernel.php中注册此包
-
更新您的composer.json,因为我们正在使用Doctrine Mocks。这不是优化过的,我该如何将其限制在测试环境中?
"autoload": { "psr-0": { "Doctrine\\Tests\\DBAL": "vendor/doctrine/dbal/tests/" } }
-
/!\ 确保您为测试设置了另一个数据库,因为套件将破坏数据库!
-
运行!
需求
- WordPress >=3.4.2 和 <=3.5
注意事项
- WordPress假定它将在全局范围内运行,因此其部分代码甚至不担心显式地全局化变量。WordPress核心所需版本略微改善了这种情况(足以让我们与之集成),但请注意,WordPress的其他部分或插件可能仍然存在相关问题。