我需要在fieldset的getInputFilterSpecification方法中使用验证器链来使用breakChainOnFailure参数并只获取一条错误消息.
我知道使用InputFilter类生成验证器链如何解释zend文档,例如
$input = new Input('foo');
$input->getFilterChain()
->attachByName('stringtrim', true) //here there is a breakChainOnFailure
->attachByName('alpha');
Run Code Online (Sandbox Code Playgroud)
但我想用工厂格式做同样的事情.我在哪里可以将breakChainOnFailure参数放在此示例中:
$factory = new Factory();
$inputFilter = $factory->createInputFilter(array(
'password' => array(
'name' => 'password',
'required' => true,
'validators' => array(
array(
'name' => 'not_empty',
),
array(
'name' => 'string_length',
),
),
),
));
Run Code Online (Sandbox Code Playgroud) 我如何翻译字符串,其中$ user包含用户名?
$message = 'Hello ' . $user . ', how are you';
Run Code Online (Sandbox Code Playgroud)
如果我使用以下代码进行翻译,则无效.
$message = $translator->translate('Hello ' . $user . ', how are you');
Run Code Online (Sandbox Code Playgroud)
在我的en_EN.po文件中,我有:
msgid "Hello %s, how are you"
msgstr ""
Run Code Online (Sandbox Code Playgroud)
在我的es_ES.po文件中,我有:
msgid "Hello %s, how are you"
msgstr "Hola %s, como estas"
Run Code Online (Sandbox Code Playgroud)
提前致谢.
如何使用PHP基本异常在zend框架2中捕获异常?
如果取消注释行,则找不到Exception类,并且取消捕获异常.
如果对行进行注释,则命名空间为null,并且建立PHP基本异常类.
我无法取消注释这一行,因为zend在很多地方都需要它,ig ActionController.
怎么样?
我是否只使用Zend Exceptions?我必须使用什么是更通用的zend Exception类?
<?php namespace SecureDraw; ?> // <<----- If remove this line catch work ok!!
<?php echo $this->doctype(); ?>
<?php
use Zend\Db\Adapter\Adapter as DbAdapter;
try{
$dbAdapter = new DbAdapter(array(
'driver' => 'Pdo_Mysql',
'database' => 'securedraw',
'username' => 'root',
'password' => '',
));
$sql = "select * from tablenotexist";
$statement = $dbAdapter->createStatement($sql);
$sqlResult = $statement->execute();
}
catch(Exception $e){
echo "hello";
}
?>
Run Code Online (Sandbox Code Playgroud)