为什么symfony 2同时使用deps
文件和composer.json
文件?
我可以看到一些文件告诉我:
php bin/vendors install
Run Code Online (Sandbox Code Playgroud)
而另一方告诉我:
php composer.phar install
Run Code Online (Sandbox Code Playgroud) 我刚刚安装了最后一个版本的phpunit,当我运行演示测试时:
bin/phpunit src/Acme/DemoBundle/Tests/
Run Code Online (Sandbox Code Playgroud)
我遇到了这个问题:
1) Acme\DemoBundle\Tests\Controller\DemoControllerTest::testIndex
RuntimeException: Unable to guess the Kernel directory.
Run Code Online (Sandbox Code Playgroud)
以及内核被引用的行
关于为什么这个DEMO TEST不起作用的任何想法?
在尝试创建外键映射(即将Category映射到Product)时,我在"Create Product"页面中收到以下错误:
在传递给选择字段的"CJ\BusinessBundle\Entity\Category"类型的对象上找不到"__toString()"方法.要改为读取自定义getter,请将选项"property"设置为所需的属性路径.
我一直在尝试使用Symfony2创建一个登录表单,用户可以使用他们的电子邮件地址和密码登录.我遇到了很多问题,最后意识到只有$username
在我的AdminUser
实体类中有一个属性才会有效.我试图在可能的情况下使用电子邮件而不是用户名,所以有人可以解释为什么$username
需要或我出错的地方?此外,在我的login.html.twig
文件中我仍在使用_username
而不是_email
如果这有什么区别?我的代码如下(我删除了一些不适用的getter和setter):
管理员实体:
namespace XXX\WebsiteBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* AdminUser
*
* @ORM\Table(name="admin_user",indexes={@ORM\Index(name="indexes", columns={"deleted"})})
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class AdminUser implements UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=45)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=45, unique=true)
*/
private $email;
/** …
Run Code Online (Sandbox Code Playgroud) 我正试图获得一个AJAX响应,所以我可以摆弄它,使我的表单更容易使用.当我使控制器(下面的代码)返回正常响应时var_dump()
,我得到对象的输出,所以我知道查询没有错(我使用ID 1来查询调试).但是,当我返回输出时json_encode()
,我只得到一个空的JSON文件.
<div id="content">
<form id="myForm" action="{{path('snow_ajax')}}" method="POST" >
Write your name here:
<input type="text" name="name" id="name_id" value="" /><br />
<input type="submit" value="Send" />
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript">
$(document).ready(function() {
$("#myForm").submit(function(){
var url=$("#myForm").attr("action");
$.post(url,{
formName:"ajaxtest",
other:"attributes"
},function(data){
if(data.responseCode==200 ){
alert("Got your json!");
}
else{
alert("something went wrong :(");
}
});
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
public function ajaxAction()
{
$location = $this->getDoctrine()->getRepository('SnowFrontBundle:Location')
->find(1);
$output = var_dump($location);
return $output;
}
Run Code Online (Sandbox Code Playgroud)
public function …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在MAMP中配置Symfony2框架.
然而,在php.ini
我已正确设置的date.timezone
情况下,MAMP似乎以某种方式覆盖了设置并改为使用系统时间.
因此,Symphony的config.php
页面发出此警告:
警告:date_default_timezone_get()[function.date-default-timezone-get]:依赖系统的时区设置是不安全的.您需要使用date.timezone设置或date_default_timezone_set()函数.如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能拼错了时区标识符.我们在第434行的/Applications/MAMP/htdocs/Symfony/app/SymfonyRequirements.php中选择'America/New_York'作为'EST/-5.0/no DST'
在修复此问题之前,Symfony无法显示启动页面.什么是解决方案?
谢谢!
我的行动:
$matches_request = $em->getRepository('Bundle:ChanceMatch')->findByRequestUser(1);
$matches_reply = $em->getRepository('Bundle:ChanceMatch')->findByReplyUser(1);
Run Code Online (Sandbox Code Playgroud)
是否可以or
使用getRepository 加入查询条件,例如.
$matches_reply = $em->getRepository('FrontendChancesBundle:ChanceMatch')->findBy(array('requestUser' => 1, 'replyUser' => 1);
//this of course gives me the a result when `requestUser` and `replyUser` is `1`.
Run Code Online (Sandbox Code Playgroud)
我的桌子
id | requestUser | replyUser
....
12 | 1 | 2
13 | 5 | 1
Run Code Online (Sandbox Code Playgroud)
我的查询应该返回id 12 & 13
.
感谢帮助!
symfony ×7
doctrine ×2
doctrine-orm ×2
php ×2
ajax ×1
entity ×1
login ×1
mamp ×1
mysql ×1
phpunit ×1
symfony-2.1 ×1
symfony-2.2 ×1
testing ×1