我nesbo/carbon
在我的vendor
文件夹中找到了.这是一个非常有用的库,我很想知道我安装的其他软件包需要它.
我怎么知道这个?
在Symfony中,建议最佳实践不要使用bundle来组织业务逻辑.
只有在其中的代码要在其他应用程序中按原样重用时,才应使用这些bundle:
但捆绑包意味着可以作为独立软件重用的东西.如果UserBundle不能在其他Symfony应用程序中"按原样"使用,那么它不应该是自己的捆绑包.
因此,当我将我的应用程序从Symfony 3.3升级到Symfony 4时,我认为现在是重组我的代码的合适时机.
目前我已经遵循"捆绑式结构":
- src
- AppBundle
- Controller
- Entity
- Repository
- Resources
- ...
- MyNamespace
- Bundle
- BundleTodo
- Controller
- Entity
- Repository
- Resources
- ...
- BundleCatalog
- Controller
- Entity
- Repository
- Resources
- ...
- BundleCart
- Controller
- Entity
- Repository
- Resources
- ...
- ...
Run Code Online (Sandbox Code Playgroud)
现在,使用新的目录结构,我应该如何组织我的代码?
我想用这种方式组织它:
-src
- Core
- Controller
- Entity
- Repository
- .. …
Run Code Online (Sandbox Code Playgroud) 我必须检查一个Email
实体是否已经存在ArrayCollection
但我必须对电子邮件进行检查作为字符串(实体包含一个ID和一些与其他entites的关系,因此我使用一个单独的表来保存所有电子邮件).
现在,在第一次我写这个代码:
/**
* A new Email is adding: check if it already exists.
*
* In a normal scenario we should use $this->emails->contains().
* But it is possible the email comes from the setPrimaryEmail method.
* In this case, the object is created from scratch and so it is possible it contains a string email that is
* already present but that is not recognizable as the Email object that contains it is created from …
Run Code Online (Sandbox Code Playgroud) 以下代码用于从php中查找字符串中的url.这是代码:
$string = "Hello http://www.bytes.com world www.yahoo.com";
preg_match('/(http:\/\/[^\s]+)/', $string, $text);
$hypertext = "<a href=\"". $text[0] . "\">" . $text[0] . "</a>";
$newString = preg_replace('/(http:\/\/[^\s]+)/', $hypertext, $string);
echo $newString;
Run Code Online (Sandbox Code Playgroud)
好吧,它显示了一个链接,但如果我提供的链接不起作用,它也不起作用,如果我没有http://写,那么它不会显示链接.我想要提供的任何链接都应该是活动的,比如stackoverflow.com.
任何帮助请..
我已成功将我的Symfony 2应用程序部署到Heroku但现在,当我尝试访问它时,我收到以下403错误:
被禁止
您无权访问此服务器上的/.
这是Heroku的日志:
2015-07-29T14:31:41.827491+00:00 heroku[router]: at=info method=GET path="/" host=my-app.herokuapp.com request_id=557a70f4-ea11-4519-b8df-301b714f6ffa fwd="151.77.103.253" dyno=web.1 connect=0ms service=1ms status=403 bytes=387
2015-07-29T14:31:41.828428+00:00 app[web.1]: [Wed Jul 29 14:31:41.827438 2015] [autoindex:error] [pid 104:tid 140466989270784] [client 10.100.0.139:16096] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive
2015-07-29T14:31:41.829009+00:00 app[web.1]: 10.100.0.139 - - [29/Jul/2015:14:31:41 +0000] "GET / HTTP/1.1" 403 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
似乎Symfony(或Heroku?)正在尝试提供目录,/app/
但我认为这是不正确的,如日志:
2015-07-29T14:31:41.828428 + …
php heroku http-status-code-403 http-status-code-404 symfony
导航我使用Symfony构建的应用程序我发现一些实体的映射是不一致的.
Symfony Profiler告诉我这个:
AppBundle\Entity\Email映射AppBundle\Entity\Email#forCustomer和AppBundle\Entity\Customer #eversils彼此不一致.
反过来:
AppBundle\Entity\Customer关联AppBundle\Entity\Customer #emails指的是不存在的拥有方字段AppBundle\Entity\Email#owner.
如何在一次检查所有实体以发现这种不一致,而不必浏览所有应用程序希望我发现其他不一致?
在Doctrine文档中有以下代码:
<?php
// update_product.php <id> <new-name>
require_once "bootstrap.php";
$id = $argv[1];
$newName = $argv[2];
$product = $entityManager->find('Product', $id);
if ($product === null) {
echo "Product $id does not exist.\n";
exit(1);
}
$product->setName($newName);
$entityManager->flush();
Run Code Online (Sandbox Code Playgroud)
我不明白的是最后一部分,在设置产品名称后$product->setName()
,$entityManager->flush()
调用该方法:
$product->setName($newName);
$entityManager->flush();
Run Code Online (Sandbox Code Playgroud)
在我看来,$product
变量和$entityManager
变量之间没有任何联系,除了$product
应该包含该$entityManager->find()
方法的响应的事实.
怎样$entityManager->flush()
才能读取设定的值$product->setName()
?
我正在尝试为Symfony中构建的表单中的字段禁用前端HTML5验证.
在Twig中,我使用此代码:
{{ form_widget(form.email, {'attr': {'class': 'form-control input-lg','novalidate': 'novalidate}}) }}
Run Code Online (Sandbox Code Playgroud)
但该领域仍被视为必需.我究竟做错了什么?
为了管理我的库我使用Composer,所以我设置了依赖项composer.json
,然后添加(永远composer.json
)代码所在的私有存储库的远程地址.
运行时,composer update/install
我被提示请求访问这些私有存储库的密钥.
现在,我正在尝试将Symfony 2应用程序部署到Heroku.
当Heroku尝试从我的私有存储库下载软件包时出现问题:我如何向Heroku提供对这些存储库的访问?
这是一个示例composer.json配置:
"require": {
"my/private-package": "~1.0",
},
"repositories": [
{
"type": "git",
"url": "https://Aerendir@bitbucket.org/Aerendir/private-package"
}
]
Run Code Online (Sandbox Code Playgroud)
这个配置在作曲家文档中有解释(它也可以在没有Satis的情况下工作,除了Heroku :)的"问题" - 或者我认为的其他云托管.
在那里,关于身份验证,解释:
请注意,如果您的私有软件包托管在GitHub上,您的服务器应该有一个ssh密钥,使其能够访问这些软件包,然后您应该在命令中添加--no-interaction(或-n)标志以确保它回退到ssh密钥身份验证而不是提示输入密码.这对于持续集成服务器来说也是一个很好的技巧.
现在,问题是2:
那么,我怎样才能让Heroku访问BitBucket上的私有存储库?
如何从composer install
Heroku部署的命令下载BitBucket上托管的私有存储库?
我已更新到Symfony 2.8.调试工具栏告诉我很多不推荐的调用,但大多数都是第三方捆绑.
有没有办法过滤掉这些弃用通知,所以我只能看到来自我的捆绑包的那些?这样我可以解决它们,而目前我必须深入了解很多通知,也许我会失去一些不赞成的电话.
symfony ×6
php ×5
doctrine-orm ×3
composer-php ×2
heroku ×2
debugging ×1
deployment ×1
doctrine ×1
forms ×1
git ×1
mapping ×1
orm ×1
ssh ×1
symfony4 ×1
twig ×1