我正在设置 jenkins 作业来构建和部署 Zend Framework 2 php 应用程序。在我的 ant 构建脚本中,我定义了一个用于验证 php 文件的 lint 作业。
构建作业失败,因为 lint 在 ZF2 库文件中检测到错误。
这是 lint 生成的输出:
[apply] PHP Fatal error: Constructor Zend\Captcha\Factory::factory() cannot be static in /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php on line 90
[apply] Errors parsing /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么验证Zend/Captcha/Factory.php fails?
ANT 任务如下所示:
<target name="lint" description="Perform syntax check of sourcecode files">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
Run Code Online (Sandbox Code Playgroud) 你如何(优雅地)使用Zend Framework 2中的闭包来按字段排序select语句?
我有以下PHP代码:
$gateway = new \Zend\Db\TableGateway\TableGateway('table_name', $adapter);
$select = $gateway->select(function($select){
$select->where->in('id', array(4, 2, 3, 1));
// insert some awesome ordering magic here..!
});
Run Code Online (Sandbox Code Playgroud)
我知道你可以很容易地做到这一点:
...
$select->order(array('id ASC'));
...
Run Code Online (Sandbox Code Playgroud)
但是,这只是按升序id值排序结果,我需要通过特定的id序列对它们进行排序(即:按序列排序)4, 2, 3, 1.
是否有一个优雅的Zend Framework 2功能,我可以在这里使用id它们自己订购?有效地创建SQL:
select * from table_name
where 'id' in (4, 2, 3, 1)
order by field('id', (4, 2, 3, 1));
Run Code Online (Sandbox Code Playgroud) 我有一个在表单中使用的集合,我知道,如果我想在普通元素中设置一个值,我使用:
$form->get('submit')->setValue('Update');
Run Code Online (Sandbox Code Playgroud)
如何在"地址"字段中设置值例如"'在集合中''"我使用zend Framework 2".
$companies = $this->getCompaniesTable()->getCompanies($id);
$form = new CompaniesForm();
$form->bind($companies);
$form->get('submit')->setValue('Update');
$form->get('submit')->setValue('Update');
$form->get('address')->setValue('test address');
Run Code Online (Sandbox Code Playgroud)
最后一行的上一页.代码不起作用,有什么问题?!
表单代码是:
<?php
namespace Companies\Form;
//use Zend\Form\Element;
use Zend\Form\Form;
class CompaniesForm extends Form {
public function __construct($name = null) {
parent::__construct('companies');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype', 'multipart/form-data');
$this->add(array(
'name' => 'id',
'type' => 'Hidden'
));
$this->add(array(
'name' => 'name',
'type' => 'Text'
));
// address field
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'address',
'options' => array(
'count' => 1,
'should_create_template' => false,
'allow_add' => true, …Run Code Online (Sandbox Code Playgroud) 我有以下学说模型..
众议院主义实体
// Below are not my real object. These are example similar to my originals
// Doctrine entity
class House implements JsonSerializable {
// Doctrine properties
protected $id; // doctrine id field
protected $rooms; // rooms : one-to-many relation to Room doctrine entity.
// serializer
public function jsonSerialize() {
return [
'id' => $this->GetId(),
'rooms' => $this->GetRooms(),
];
}
// Getters & setters.
public GetId() { return $this->id; }
public SetId($id) { $this->id = $id }
public GetRooms() { …Run Code Online (Sandbox Code Playgroud) 我在 Zend Framework 2 应用程序中上传图像时遇到问题,我想我的代码中某处存在配置错误。
这是我目前的代码。我像 ZfcUser 表单一样创建了表单和过滤器。
表单扩展提供事件表单(ZfcBase)
$file = new Element\File('image');
$file->setLabelAttributes(array('class' => 'control-label col-sm-4'));
$file->setLabel('image');
$this->add($file);
Run Code Online (Sandbox Code Playgroud)
过滤器扩展提供事件输入过滤器(ZfcBase)
$this->add(
array(
'type' => 'Zend\InputFilter\FileInput',
'name' => 'image',
'required' => true,
'validators' => array(
array(
'name' => 'File\UploadFile',
),
),
'filters' => array(
array(
'name' => 'File\RenameUpload',
'options' => array(
'target' => './public/img/uploads',
'randomize' => true,
),
),
),
)
);
Run Code Online (Sandbox Code Playgroud)
在验证过程中,方法 FileInput::isValid() 被调用 - 但值始终为空,我不知道为什么会这样。
HTML-Form设置为multipart/form-data,Server配置也没有问题。我用于测试的文件只有 80KB。
任何人的想法,有什么问题?
我创建了一个表单输入
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'UserRestorePassword.Restore',
'id' => 'submitbutton',
'class' => 'btn btn-primary btn-sm',
'style' => 'padding: 7px 35px;'
),
));
这会产生:
<input name="submit" type="submit" id="submitbutton" class="btn btn-primary btn-sm" style="padding: 7px 35px;" value="Restore">
Run Code Online (Sandbox Code Playgroud)
鉴于:
<?=$this->translate($this->formSubmit($form->get('submit')));?>
Run Code Online (Sandbox Code Playgroud)
如何Restore从这种形式中获得价值?
在我的 ZF2 应用程序中,我添加了以下事件侦听器,但是我想让操作的执行实际停止,但这不会发生。
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use ($controller) {
$request = $e->getRequest();
$method = $request->getMethod();
$headers = $request->getHeaders();
// If we get here, based on some conditions, the original intended action must return a new JsonViewModel()...
return new JsonViewModel([]); // However, this doesn't do anything.
}, 100); // execute before executing action logic
}
Run Code Online (Sandbox Code Playgroud) 我使用ZF2来创建新的应用程序。关于控制器和模型文件下的数据库连接,我们存在一些问题。
我们已经将所有数据库凭据放入“ global.php”和“ db.local.php”中,并且还在“ Module.php”文件中获取了数据库适配器访问权限,但是我们没有在控制器和模型文件中获取数据库连接,并且没有在控制器和模型下运行查询。
这是我的代码:
**global.php :**
return array(
'db' => array(
'driver'=> 'Pdo',
'dsn'=> 'mysql:dbname=pick_fire;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
Run Code Online (Sandbox Code Playgroud)
**db.local.php :**
<?php
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=pick_fire;host=localhost',
'username' =>'root',
'password' =>'123456',
'driver_options'=> array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'
),
),
'service_manager' => array(
'aliases' => array(
'db' => 'Zend\Db\Adapter\Adapter',
),
),);
----------------------------------------------
**Module.php :**
public …Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试进行Ldap身份验证,遵循以下文档
https://zf2.readthedocs.org/en/latest/user-guide/skeleton-application.html
我只是用'Auth'模块替换'Album'模块,并使用Ldap autentication的示例代码
https://zf2.readthedocs.org/en/latest/modules/zend.authentication.adapter.ldap.html
但是我收到这个错误,当我提交带有登录数据的表单时,Zend无法找到Ldap类.
致命错误:在第139行的C:\ wamp\www\sade\vendor\zendframework\zend-authentication\src\Adapter\Ldap.php中找不到类'Zend\Ldap\Ldap'
我正在使用作曲家,对于zend框架和模块的atuoloader,我已经有错误相关的类没有找到但是我自己的类,而不是像Ldap这样的Zend类.
谢谢.
这是文件和文件夹的结构
/module
/Auth
/config
module.config.php
/src
/Auth
/Controller
AuthController.php
/Form
AuthForm.php
/Model
Auth.php
/view
/auth
/auth
index.php
Module.php
Run Code Online (Sandbox Code Playgroud)
以及该模块的主要代码:
module.config.php
return array(
'controllers' => array(
'invokables' => array(
'Auth\Controller\Auth' => 'Auth\Controller\AuthController',
),
),
'router' => array(
'routes' => array(
'auth' => array(
'type' => 'segment',
'options' => array(
'route' => '/auth[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Auth\Controller\Auth',
'action' => 'index', …Run Code Online (Sandbox Code Playgroud) 是什么决定了ZF2中的视图文件夹结构?我使用Album应用程序跟踪了最初的ZF2教程,并注意到相册模块的视图位置/module/Album/view/album/album/*.phtml.
是什么决定了这一/album/album/部分?
为什么这些目录都是小写的?
为什么嵌套的名字相同?
在什么情况下他们会不一样?
我假设答案在module.config.php文件中.但是我尝试使用3个实例的组合album来尝试将每个实例album1单独更改以查看其具有的效果.这是我module.config.php的旁边评论的每个更改的结果.
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => array( //When switching to `album1` I get "Route with name "album" not found"
//If this is anything but `album` I get this error, regardless of the …Run Code Online (Sandbox Code Playgroud) zend-framework2 ×10
php ×8
doctrine-orm ×1
file-upload ×1
jenkins ×1
json ×1
ldap ×1
mysql ×1
phplint ×1
routes ×1
validation ×1
zend-db ×1