当前位置: 首页 > news >正文

网站建设流程体会wordpress查看文章id

网站建设流程体会,wordpress查看文章id,外贸企业查询,重庆网站推广软件一、Bean 在 Swoft 中#xff0c;一个 Bean 就是一个类的一个对象实例。 它(Bean)是通过容器来存放和管理整个生命周期的。 最直观的感受就是省去了频繁new的过程#xff0c;节省了资源的开销。 二、Bean的使用 1、创建Bean 在【gateway/app/Http/Controller】下新建一个名为… 一、Bean 在 Swoft 中一个 Bean 就是一个类的一个对象实例。 它(Bean)是通过容器来存放和管理整个生命周期的。 最直观的感受就是省去了频繁new的过程节省了资源的开销。 二、Bean的使用 1、创建Bean 在【gateway/app/Http/Controller】下新建一个名为【TestController.php】的文件文件内容如下。注释“gateway”为我的项目名称。 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace App\Http\Controller;use Swoft\Http\Server\Annotation\Mapping\RequestMapping; use Swoft\Bean\Annotation\Mapping\Bean;/*** Class TestController** since 2.0* Bean()*/ class TestController {/*** RequestMapping(index)**/public function index(){return testBean;} }2、调用Bean 在【gateway/app/Http/Controller】目录下随便找个已近存在的文件进行编辑调用本文就选择了【RpcController.php】文件这个文件在项目创建之初就存在了。 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace App\Http\Controller;use Swoft\Bean\BeanFactory; use Swoft\Http\Server\Annotation\Mapping\Controller; use Swoft\Http\Server\Annotation\Mapping\RequestMapping;/*** Class RpcController** since 2.0** Controller()*/ class RpcController {/*** RequestMapping(list)* return array*/public function getList(): array{$bean BeanFactory::getBean(TestController::class);return [$bean-index()];}}3、展示结果 在【TestController】文件中的【index】方法中返回的内容是“testBean“调用的时候返回了一个数组。我的浏览器安装了JSON的格式化工具所以返回的数据都格式化了。 4、说明 在上面两个文件中都有标红的地方两个文件的标红处是有关联的。 1、在【TestController】文件中Bean的写法有很多种如下所示 第一种   写法Bean()  调用BeanFactory::getBean(TestController::class); 第二种   写法Bean(testBean)  调用BeanFactory::getBean(testBean);  注意点Bean(testBean)中的引号一定要双引号单引号要报错。 第三种   写法Bean(nametestBean,scopeBean::SINGLETON)  调用BeanFactory::getBean(testBean);  注意点scopeBean::SINGLETON 中的scope有三个值分别是 Bean::SINGLETON(默认), Bean::PROTOTYPE, Bean::REQUEST。 第四种   写法Bean(nametestBean,scopeBean::SINGLETON,aliastestBeanAlias)  调用BeanFactory::getBean(testBeanAlias);  注意点alias 表示别名的意思使用了 alias 那么在调用时可以用别名调用。当然设置别名后也可以不用别名调用还是用原来的name也是可以的。 2、关于Bean的源码可以打开【gateway/vendor/swoft/bean/src/Annotation/Mapping/Bean.php】文件查看。我下载的Swoft版本是2.0的Bean.php文件内容如下 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace Swoft\Bean\Annotation\Mapping;use Doctrine\Common\Annotations\Annotation\Attribute; use Doctrine\Common\Annotations\Annotation\Attributes; use Doctrine\Common\Annotations\Annotation\Enum; use Doctrine\Common\Annotations\Annotation\Target;/*** Class Bean** Annotation* Target(CLASS)* Attributes({* Attribute(name, typestring),* Attribute(scope, typestring),* Attribute(alias, typestring),* })** since 2.0*/ final class Bean {/*** Singleton bean*/public const SINGLETON singleton;/*** New bean*/public const PROTOTYPE prototype;/*** New bean from every request*/public const REQUEST request;/*** New bean for one session*/public const SESSION session;/*** Bean name** var string*/private $name ;/*** Bean scope** var string* Enum({Bean::SINGLETON, Bean::PROTOTYPE, Bean::REQUEST})*/private $scope self::SINGLETON;/*** Bean alias** var string*/private $alias ;/*** Bean constructor.** param array $values*/public function __construct(array $values){if (isset($values[value])) {$this-name $values[value];}if (isset($values[name])) {$this-name $values[name];}if (isset($values[scope])) {$this-scope $values[scope];}if (isset($values[alias])) {$this-alias $values[alias];}}/*** return string*/public function getName(): string{return $this-name;}/*** return string*/public function getScope(): string{return $this-scope;}/*** return string*/public function getAlias(): string{return $this-alias;} }
http://www.yayakq.cn/news/5869/

相关文章:

  • php网站开发实例视频教程高德vr全景地图下载
  • 初创公司网站设计苏州分销平台是什么意思
  • 相城做网站的公司织梦网站地图自动更新
  • 被墙网站查询flash互动网站开发
  • 对网站建设的意见建议嘉兴优化网站公司哪家好
  • 闵行交大网站建设网业大全
  • 建网站设公司韩国最新新闻事件
  • 网站设计的总结网站的外链接数
  • 长春网站建设公司排名前十wordpress首页广告
  • 什么是部署php网站西红门做网站
  • 淘宝网站开发费用镇江网站设计哪家好
  • 做国外网站做什么内容好VIP视频网站有得做吗
  • 做网站对公司的作用猎头公司联系方式
  • 科技公司网站制作模板wordpress中文版兼容性问题
  • 龙华网站建设设计公司大连网站制作团队
  • 平原县网站seo优化排名郑州好的网站建设公司排名
  • 教育视频网站开发软件项目管理工具
  • 广东微信网站推广哪家专业wordpress 七牛云图床
  • 网站建设和管理是教什么科目杭州服装设计公司
  • 好的网站搭建公司沈阳免费seo关键词优化排名
  • 驾校视频网站模板哪家公司网站做得好
  • 网站建设作业做一个简单的网站成品网站 售卖
  • 泰安可信的网站建设wordpress表单制作
  • 中国国际贸易网站西安手机网站案例
  • 网站专题怎么做小微企业建站
  • app推广平台网站学网站开发培训机构
  • 网站负责人 法人北京seo专业团队
  • 网站程序方面建筑业大数据服务平台官网
  • 爱妮微如何做网站链接的网址北京做网站设计招聘
  • 武清区网站建设中国铁建华南建设有限公司网站