我正在使用Zend Framework 2和Doctrine 2开发我的应用程序.
虽然书面方式说明,我无法理解之间的差异mappedBy和inversedBy.
我应该什么时候使用mappedBy?
我应该什么时候使用inversedBy?
我什么时候不用?
这是一个例子:
/**
*
* @ORM\OneToOne(targetEntity="\custMod\Entity\Person", mappedBy="customer")
* @ORM\JoinColumn(name="personID", referencedColumnName="id")
*/
protected $person;
/**
*
* @ORM\OneToOne(targetEntity="\Auth\Entity\User")
* @ORM\JoinColumn(name="userID", referencedColumnName="id")
*/
protected $user;
/**
*
* @ORM\ManyToOne (targetEntity="\custMod\Entity\Company", inversedBy="customer")
* @ORM\JoinColumn (name="companyID", referencedColumnName="id")
*/
protected $company;
Run Code Online (Sandbox Code Playgroud)
我做了一个快速搜索,发现了以下内容,但我仍感到困惑:
我试图仅在成功验证时提交表单.验证适用于所需但不适用于ng-minlength
表单输入无效但表单仍在提交.
<form name="myForm" ng-submit="count = count + 1" ng-init="count=0" ng-app>
<div class="control-group" ng-class="{error: myForm.mobile.$invalid}">
<label class="control-label" for="mobile">Mobile</label>
<div class="controls">
<input type="text" name="mobile" placeholder="07XXXXXXXXX" ng-model="mobile" ng-minlength="11" required />
<span ng-show="myForm.mobile.$error.required" class="help-inline">Required</span>
<span ng-show="myForm.mobile.$error.minlength" class="help-inline">Mobile number should be minimum 11 character starting from 07</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="btn" type="submit" value ="submit" />
</div>
count: {{count}}<br />
<tt>myForm.$invalid = {{myForm.$invalid}}</tt><br/>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么.
我不想使用提交按钮禁用方法.
我正在使用"doctrine/doctrine-orm-module":"0.7.0"和ZF2.
一旦我创建实体,我通常会运行以下命令来根据我的实体自动同步和生成数据库.
./vendor/bin/doctrine-module orm:validate-schema
./vendor/bin/doctrine-module orm:schema-tool:create
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个过程逆转?我的意思是,我可以在mysql中从现有数据库生成实体吗?
如何在控制器操作中呈现除默认值之外的其他视图.默认情况下,它尝试在视图文件夹中找到与操作相同的视图,但我想在视图文件夹中为控制器操作呈现不同的视图.
我们可以像这样做这个ZF1 $this->_helper->viewRenderer('foo');
任何人都知道,如何在Zendframework 2中实现上述目标?
我们可以使用禁用视图
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent("Hello World");
return $response;
Run Code Online (Sandbox Code Playgroud)
我不知道如何在zf2中更改/渲染不同的视图.
如何在div容器中验证具有三个规则和三个自定义消息的电子邮件地址字段.即.
rules: {
email: {
validationRule: true,
email: true,
remote: '/ajax/emailDuplicationCheck.php'
}
}
Run Code Online (Sandbox Code Playgroud)
如果第一条错误信息应为"验证规则失败"
如果第二个错误(失败)"输入电子邮件地址"
如果第三(远程)失败.消息应为"帐户已存在于数据库中".
我可以为所有规则添加一条消息,但我想根据规则自定义消息.
如何在dropdown/ng-options中从加载的json中获取其他属性
在ng-change上我还想传递所选对象的campaignType.
我怎么能这样做?
我的观点看起来像这样
<div ng-app>
<div ng-controller="cCtrl">
<select ng-model="campaign" ng-options="c.id as c.name for c in campaigns" ng-change="search2(c.campaignType)">
<option value="">-- choose campaign --</option>
</select>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样
function cCtrl($scope) {
$scope.campaigns = [{
"custID": 1,
"custName": "aaa ",
"msgID": 3,
"msgName": "Email Test Msg",
"id": 2,
"name": "Email Test Campaign",
"description": "Test Campaign",
"campaignType": "Email",
"created": "1374229715",
"isActive": 1,
"isDeleted": 0
}];
$scope.search2 = function (campaignType) {
alert(campaignType); // not working
alert($scope.campaign.campaignType); // not working
//console.log($scope.campaign.campaignType);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用带有ZF2的Doctrine 2 ORM.
/**
*
* @ORM\Column(type="tinyint", options={"default" = 1})
*/
protected $isActive;
Run Code Online (Sandbox Code Playgroud)
如何创建tinyint类型的列,正如我在支持数据类型的学说中看到的那样,它不存在.
Commandline># ./vendor/bin/doctrine-module orm:validate-schema
[Mapping] FAIL - The entity-class 'Application\Entity\User' mapping is invalid:
* The field 'Application\Entity\User#isActive' uses a non-existant type 'tinyint'.
[Doctrine\DBAL\DBALException]
Unknown column type "tinyint" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypeMap(). If this
error occurs during database introspection then you might have forgot to …Run Code Online (Sandbox Code Playgroud) 在Zendframework-1中,我们通常将自定义代码保存在库文件夹(与应用程序文件夹并行)下,几乎使用与zend框架(供应商)库相同的文件夹结构来创建插件或扩展核心库.
在zend框架2中,文件夹结构被更改.zend供应商核心库在Vendor文件夹下移动,应用程序文件夹移动到Module(root)文件夹中.
我的问题是,哪个是在ZF2中保存自定义插件/代码库文件夹的最佳位置?
还有其他人经历过这个阶段吗?
我试图在zf2中创建一个简单的服务,我可以在viewhelper中使用它
步骤1.我在src/Application/Service/Service1.php中创建了一个类,如下所示
namespace Application\Service;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Service1 implements ServiceLocatorAwareInterface
{
public function __construct()
{
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
}
public function getServiceLocator()
{
}
}
Run Code Online (Sandbox Code Playgroud)
Step2我在module.php文件中设置如下.
public function getServiceConfig()
{
return array(
'factories' => array(
'Application\Service\Service1' => function ($sm) {
return new \Application\Service\Service1($sm);
},
)
);
}
public function onBootstrap($e)
{
$serviceManager = $e->getApplication()->getServiceManager();
$serviceManager->get('viewhelpermanager')->setFactory('Abc', function ($sm) use ($e) {
return new \Application\View\Helper\Abc($sm);
});
}
Run Code Online (Sandbox Code Playgroud)
Step3最后我在我的视图中帮助src/Application/View/Helper/Abc.php测试()方法就像这样,II注释这行$this->sm->get('Application\Service\Service1');没有错误,必须有一些我在服务中缺少的东西?
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper; …Run Code Online (Sandbox Code Playgroud) 我试图Value is required and can't be empty在zf2中自定义默认错误消息" "
我使用以下代码在inputfilter的验证器中添加自定义默认错误消息
$inputFilter->add($factory->createInput(array(
'name' => 'username',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 4,
'max' => 20,
'messages' => array(
'isEmpty' => 'Please enter User Name between 4 to 20 character!'
),
),
),
),
)));
Run Code Online (Sandbox Code Playgroud)
但我得到了以下错误.
Zend\Validator\Exception\InvalidArgumentException
File:
/home/website/vendor/zendframework/zendframework/library/Zend/Validator/AbstractValidator.php:220
Message:
No message template exists for key 'isEmpty'
Run Code Online (Sandbox Code Playgroud)
我做错了什么?