dataspring / demo-bundle
演示包
0.1.5
2016-05-05 02:25 UTC
Requires
- php: ~5.3
This package is not auto-updated.
Last update: 2024-09-14 19:14:42 UTC
README
创建自己的Symfony2包的教程
如何进行?
1. 安装Symfony
http://symfony.cn/docs/quick_tour/the_big_picture.html
2. 创建一个新的空的symfony项目
symfony new DemoBundle 2.3
(2.3 是我的symfony版本)
3. 进入项目目录
cd DemoBundle
4. 生成一个新的包
php app/console generate:bundle
这会要求你回答问题。将包命名空间设置为 DataSpring/DemoBundle (公司名 / 包名)。
5. 进入包目录
cd src/DataSpring/DemoBundle
6. 初始化你的github仓库
首先在你的github上创建一个新的仓库,然后运行以下命令行
git init
touch README.md
git add .
git commit -m "initial commit"
git remote add origin git@github.com:YourAccount/DemoBundle.git
git push -u origin master
7. 添加一个composer.json文件
在 src/DataSpring/DemoBundle/
文件夹中,手动添加一个 composer.json
文件。
或者运行
composer init
以获取一个在修改之前的最简单文件。
一个composer.json文件看起来可能是这样的
{
"name": "dataspring/demo-bundle",
"description": "Demo Bundle",
"type": "symfony-bundle",
"keywords": ["dataspring"],
"license": "MIT",
"homepage": "http://github.com/guobinqiu/DemoBundle",
"authors": [
{
"name": "Guobin",
"email": "qracle@126.com"
}
],
"require": {
"php": "~5.3"
},
"autoload": {
"psr-4": {
"DataSpring\\DemoBundle\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "0.1.x-dev"
}
}
}
8. 添加一个MIT许可文件
在 src/DataSpring/DemoBundle/
文件夹中,添加一个 LICENSE
文件
你可以从上面的许可参考中借用作为你自己的许可内容。也请参阅 LICENSE
9. 创建一个控制器及其路由
控制器代码
<?php
namespace Dataspring\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('DataSpringDemoBundle:Default:index.html.twig');
}
}
在 src/Resources/config/routing.yml
中添加
demo_index:
path: /index
defaults: { _controller: DataSpringDemoBundle:Default:index }
注意,当你创建自己的包时,不支持 Annotation
方法!
10. 在Github上标记/发布它
git tag -a VERSION -m "MESSAGE"
git push origin VERSION
11. 将它放入Packagist
-
安装 GitHub服务钩子 以确保当你推送到GitHub时,你的包将始终立即更新
在其他项目中使用它
1. 添加Composer依赖
将其添加到composer.json文件中
{
...,
"require": {
...,
"dataspring/demo-bundle": "^0.1.4"
}
}
更新依赖
php composer.phar update dataspring/demo-bundle
或更新所有依赖
php composer.phar update
或者你可以用一条命令来完成这个操作
php composer.phar require dataspring/demo-bundle
2. 启用包
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...,
new DataSpring\DemoBundle\DataSpringDemoBundle()
);
...
}
}
3. 将其添加到你的项目主路由文件中
data_spring_demo:
resource: "@DataSpringDemoBundle/Resources/config/routing.yml"
prefix: /demo
4. 最后
在您的网络浏览器中键入 http://YourDomain:port/demo/index
以访问!