kimerikal / util-bundle
一个用于与其他bundle和语言控制一起使用的symfony2 bundle,包含一些实用类。
dev-master / 2.0.1.x-dev
2021-12-23 13:09 UTC
Requires
- php: >=7.1.1
This package is not auto-updated.
Last update: 2024-09-27 02:34:25 UTC
README
一个提供实用类和语言控制,以便与其他bundle一起使用的symfony2 bundle,以及一个具有一些别名方法的UtilController来简化操作。
安装
- 将以下行添加到composer.json中的"require"部分
"require": {
...
"kimerikal/util-bundle": "dev-master"
},
- 通过composer安装此bundle
$ composer update
- 将以下行添加到app/AppKernel.php中的bundles数组
... public function registerBundles() { $bundles = array( ... new Kimerikal\UtilBundle\KKUtilBundle(), ); } ...
完成!
使用方法
- UtilController: 要使用它,只需在任何控制器中扩展此控制器。示例
namespace Kimerikal\ExampleBundle\Controller; // Import UtilController use Kimerikal\UtilBundle\Controller\UtilController; class ExampleController extends UtilController { ... }
现在您可以从控制器发送电子邮件,添加闪存消息并像这样使用doctrine
public function exampleAction(Request $req) { // Send an email. $subject = "Sample mail"; $from = $this->parameter(UtilBundle::DEFAULT_MAIL); $to = "example@gmail.com"; $view = $this->renderView('KKExampleBundle:Mail:info-mail.html.twig', array('content' => '<h1>Sample Mail</h1><p>This is a sample</p>')); $this->mailing($subject, $from, $to, $view); // Add flash message $type = "error"; $msg = "There was an error..."; $this->flashMsg($type, $msg); // Use doctrine repository $this->doctrineRepo('KKExampleBundle:Example')->loadExample(); }
- Util 实体:有多个用于字符串、时间、图像和浏览器的实用类。
// Import StrUtil use Kimerikal\UtilBundle\Entity\StrUtil; // Import ImgUtil use Kimerikal\UtilBundle\Entity\ImgUtil; class ExampleController extends UtilController { ... public function saveWhatEver() { // Let's create a slug... $name = "What Ever's name"; // Resulting slug would be "what-ever-s-name" $slug = StrUtil::slug($name); // Resize any Image to a Fixed Size ImgUtil::resizeFixedSize($src_file, $dst_file, $dst_width, $dst_height); } ... }
更多信息请访问 Kimerikal