不是所有的linux版本都会使用bash。比如在安装基于aplinelinux的镜像,他使用/bin/sh。所以进入镜像的方法是
docker exec -it your—container /bin/sh
不是所有的linux版本都会使用bash。比如在安装基于aplinelinux的镜像,他使用/bin/sh。所以进入镜像的方法是
docker exec -it your—container /bin/sh
ibexa Exp教程2 是2阶课程。在1阶内已经完成了基本的安装,模板显示等初级教学。在本阶内主要学习以下内容:
简介
按照在1阶学到的知识,首先是创建2个新的content type:
任务1 创建入口页(Landing page)
后台Content sturcture里可以啊看到一个content tree. 这里用来组织你的内容结构。其中根内容就是站点的入口 Landing Page。 你可以创建子目录,在子目录内创建子内容。这会影响以后你页面上主菜单的显示(需要代码支持)。
任务2 使用后台site预览首页
后台site 站点是一个可视化的内容编辑器。它会根据你设定的页面布局定义(Layout)来显示初步的页面框架。
页面布局定义的key位于ezplatform_page_fieldtype.layouts
下。配置内容是在yaml里定义的。以下范例内容定义了一个名为sidebar的页面布局layout。
ezplatform_page_fieldtype:
layouts:
sidebar:
identifier: sidebar
name: Right sidebar
description: Main section with sidebar on the right
thumbnail: /assets/images/layouts/sidebar.png
template: layouts/sidebar.html.twig
zones:
first:
name: First zone
second:
name: Second zone
注意观察模板文件sidebar.html.twig, 会发现其中与配置项zones的对应关系。就是zones[n]。
这个layout模板是如何与站点的base模板绑定的呢?就是在site里,在编辑模式下,右上角的…按钮”switch layout”来定义的。
起始页面定义的key:ezplatform.system.site.content_view 。原始配置如下
ezplatform:
system:
site:
content_view:
full:
welcome_page:
template: "@ezdesign/full/welcome_page.html.twig"
match:
Id\Location: 2
params:
project_dir: '%kernel.project_dir%'
这个配置不再需要,可以删除。
在新的配置里被放到了 config/packages/view.yaml 中, 注意这个yaml文件名不包含ezplattform字样,很容易被忽略。)
Layout的key: ezpublish.system.site.page_layout
然后在 ezpublish.system.site.content_view.full下添加一个key: ‘landingg_page’, 内容是
landing_page:
template: "full/landing_page.html.twig"
match:
identifier\ContentType: "landing_page"
和
ezpublish.system.site.user.layout
任务: 在首页landing page显示一个狗的种类列表
任务: 创建功能文章
先在fieldtype里定义一个叫做“schedule” 的块,然后拥有一个名字为”featrued”的view.
随机显示特定目录下的内容。完成这个任务需要:
作为一个form,你需要在后台的form编辑器内定义好所需的字段,模板和样式表。然后在首页编辑器内,把form拖入多在的位置。
通过 form 发送经来的信息则会保存在后台 form 的 submissions 之内。
完成以上4个任务后,本教程告一段落。
pagelayout.html.twig | 顶级layout. 定义了header, footer,menu和content预留位 | 1 | |
– layouts/sidebar.html.twig | 定义了左右两栏式的页面布局。被放置到content预留位内。 | 2 | |
– full/landing_page_html.twig | 继承于pagelayout.html.twig, 填充了conent预留位 | 1.1 | views.yaml里ezpublish > system > site > content_view > full > landing_page 绑定 |
本教程主要演示了如何创建布局,创建2种内建内容类型(列表内容和计划内容),创建自定义内容类型,创建用户表单。
一开始表现是在后台无法上传图片。安装xdebug后跟踪发现是validation错误。再进入imageValidator跟踪发现是校验图片的时候,需要从上传图片的字符串中重新创建图片。再进一步发现错误是”imagescreatefromstring(): No JPEG support in this PHP build”.
查看phpfino里的gd部分,果然没有JPEG。于是修改dockerfile. 在gd install之前加上一句
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --enable-gd
RUN docker-php-ext-install gd
然后build一下,就好了。
参考
https://github.com/docker-library/php/issues/881#issuecomment-702578661
I got this error message in docker log output:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003
I could not connect xdebug in phpstorm. I checked port config, it is correct. But I am not sure, where the message “host.docker.internal” come from. Until I found here:
https://github.com/docker/for-linux/issues/264#issuecomment-381437057
and
So I add following config in my compose.yml for web server.
...
extra_hosts:
- "host.docker.internal:192.168.2.193"
...
After rebuild the image, you can check your hosts file in container. It has a new line in /etc/hosts, like
192.168.2.193 host.docker.internal
This is IP from my host, on that is runing phpstorm with listen to port 9003. And it works. Of course you must install xdebug and enbalbe it first. And check your php.ini the section:
[xdebug]
xdebug.mode=coverage
xdebug.client_host=localhost
xdebug.client_port=9003
xdebug.start_with_request=yes
三篇文章帮你理解Repository设计模式和运用.
我刚开始接触symfony的时候,觉得entity, repo类似zend framework里面的model和mapper的关系。 model是数据模型, mapper是操作数据模型。 显然这种理解是肤浅的。
Entity和Repo的概念是在DDD里面提出来的。详细的说明推荐阅读:殷浩详解DDD系列 第三讲 – Repository模式。 在这篇文章中,剖析Repo的本质比较透彻。他用的是Java世界的实现。在PHP世界,特别是Symfon框架内,与之相比又有一些比较特殊的地方。
Repo是一种规范,用来隔离Entity(实体,领域内的模型)和DO(数据模型,持久层的数据模型)。
1. Repo的使用“中性”的动词,而不该使用数据持久层的专用动词, 比如避免使用 select, insert, , update, delete这样的动词作为方法名。
2. Repo是服务于Entity的,同时自身不该直接操作DO(比如数据库)。 所以推荐动词find
、save
、remove
来作为方法名
在接触这些信息之前,我曾经在DH项目里自己实现过对DDD的理解。当时我理解的领域内的模型,就类似一个需要同时修改多个数据表的模型。
在这篇文章中, 作者在symfony框架中如何使用Repo 发表了见解。 首先,他否定了symfony文档中的范例。在这个范例中,文档作者在controller里面通过继承获得的doctrie对象来获取entity manager, 然后用它创建Repo对象。作者说只有初学者才会在实际工作中使用这种方法,因为依赖被写死了。他建议使用service.
写一个repo service, 让controller只依赖这个service. 在这个service里,通过注入repo对象。然后repo对象也不要使用继承获得的findAll等方法,而只使用自家的方法。 作者称为”use composition instead of inheritance”. 所以需要写一个repo的interface,然后把自家的方法都在这个interface内定义好。这样写的好处是,脱耦。
结果调用关系就从
controller -> doctrine -> manager -> repo -> doctrine
变为了
controller-> service -> repo -> doctrine
这样的写的好处就是分层了。
在这篇文章内,不直接使用doctrine,而使用service,称为放弃 Service Locator Pattern ( 设计模式)而是使用 Dependcy injection (依赖注入模式)
不直接使用继承获得的方法,而是调用自己的方法叫做避免违反 Low of demeter 迪米特法则 (介绍)
分层好处的体现:
测试容易了。由于每一层只调用自己的下一层,所以mock起来特别方便。 要测试conterller只需要模拟一个service. 要测试service只需要模拟一个repo. 测试repo只需要模拟一个doctrine。避免了复杂的依赖关系
扩展容易了。比如如果需要在每次保存对象后触发一个事件,那么只要扩展service层就可以了。这样controller可以一直保持苗条。
看了这篇文章 ,接触到一个概念, value object. 所谓value object是用来保存value的一种对象。这种对象的几个主要特征是
关心值本身而不是基于id的
不可变 (immutable). 意思就是说,只有getter方法, 没有setter等等可从外边改变该对象的方法。该对象的值在创建对象的时候通过构造函数就被确定了,且不能再被修改了。
使用场景
在symfony的form里,用户通过表单提交来创建一个新的value object. 当用户通过表单编辑对象的时候,本能的会想到调用setter方法来修改对象。但是这会失败,因为value object没有setter方法。 这时候需要实现额外的interface,来实现这些个功能。最后在Type (关于symfony的form type是另外一个抽象概念,看文档)里面,把这个方法设置为formBuilder的DataMapper方法。
Till now, I need to run docker with sudo. To solve this, just need to add current user to docker group.
(options if no docker group exists) sudo groupadd docker
sudo gpasswd -a {username} docker
That’s all.
今天面试的时候,被问了一个问题我不知道的就是Vanish服务器。事后我查了一下。
中文介绍
https://www.w3cplus.com/performance/using-edge-side-includes-in-varnish.html
英语介绍
https://www.smashingmagazine.com/2015/02/using-edge-side-includes-in-varnish/
在这里记录一下。
sudo apt install php-dev php-pear
sudo pecl install mongodb
add mongodb.so in php.ini
just with two simple Symfony commands are all model php files is genereated. It is so cool.
php bin/console doctrine:mapping:import “App\Entity” annotation –path=src/Entity |
for getter/setter
php bin/console make:entity –regenerate App |
Source: https://symfony.com/doc/current/doctrine/reverse_engineering.html