我已经体验过Zend Framework 1,并且我已经使用该框架构建了一些应用程序.
现在,我正在试验Zend Framework 2,但我坚持使用url参数.我设置了这样的路由:
// Setup for router and routes
'Zend\Mvc\Router\RouteStack' => array(
'parameters' => array(
'routes' => array(
'default' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:slug]',
'constraints' => array(
'slug' => '[a-zA-Z][a-zA-Z0-9_\/-]*'
),
'defaults' => array(
'controller' => 'Htmlsite\Controller\BootController',
'action' => 'index',
'slug' => 'home'
),
),
),
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Htmlsite\Controller\BootController',
'action' => 'index',
),
),
),
), …Run Code Online (Sandbox Code Playgroud) 对于我们的新项目,我们已经开始使用Zend Framework 2和Dojo 1.8.ZF2有一个完全重写的表单模块,现在它具有用于一对多关系的新CollectionElement.关于UI我发现,dgrid最适合这种关系(使用编辑器列插件),所以我开始扩展FormCollection,FormRow和FormElement视图助手,这样他们就可以渲染所需的dgrid.一切都很好,直到我意识到,我不能为dgrid小部件设置每行输入名称.
我开始使用ZF2文档来修复表单集合.可以看到,集合输入元素具有类似数组的名称
order[products][0][name]
order[products][0][price]
order[products][1][name]
order[products][1][price]
Run Code Online (Sandbox Code Playgroud)
另一方面,dgrid的配置是基于列的,所以我可以有一个列定义
editor({
field: "_dojo_textbox_505ee3a390d705_26717315",
label: "Name",
editorArgs: {
name: "order[products][{index}][name]",
}
}, TextBox)
Run Code Online (Sandbox Code Playgroud)
此列定义将为所有行定义相同的窗口小部件名称,这不适用于ZF2集合数据格式要求.
我也尝试过这样命名列:
order[products][]
Run Code Online (Sandbox Code Playgroud)
哪个有效,但不允许所需的格式
order[products][][name]
Run Code Online (Sandbox Code Playgroud)
也许有办法发布这样的数据:
order[products][name][]
Run Code Online (Sandbox Code Playgroud)
然后让它转换,但解决方案看起来不正确.除此之外,我试图生成可重用的代码,并希望避免每个表单的数据修改.
由于我非常努力避免onSubmit/onClick事件处理进行数据转换,因此有两种可能的解决方案:1.使dgrid能够设置每行小部件名称2.使ZF2表单理解一些非标准的POST格式集合
不幸的是,我没有想法,这些解决方案是如何完成的,所以如果你能帮我解决这个问题,我将非常感激!
由于这与我当前的问题有些相关,我将把它放在这里作为一个附带问题:除了这个UI解决方案,你还使用什么来实现与dojo的一对多表单接口?
我有一个我的所有视图使用的布局,我需要从控制器分配一个变量到这个布局,如果我在控制器上使用此方法它不起作用:
public function indexAction()
{
return new ViewModel( array(
'testvar' => 'bla',
));
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
谢谢
我正在使用Zend/Form向我的页面添加表单.
我通过定义如下来添加元素:
$this->add(array(
'name' => 'value',
'attributes' => array(
'type' => 'text',
'id' => 'value',
'autocomplete' => 'off',
'placeholder' => 'Cost',
),
'options' => array(
'label' => 'Cost',
),
));
Run Code Online (Sandbox Code Playgroud)
如您所见,有一个'label'=>'cost'节点,这会生成一个与input元素一起使用的标签.
如何向此标签添加类,属性?
我是Zend的初学者.我may_terminate在模块路由配置中看到过.我不明白它的用途.根据ZF2官方文档,
the option “may_terminate” hints to the router that no other
segments will follow it.
Run Code Online (Sandbox Code Playgroud)
我仍然没有得到的含义no other segments will follow it.这是什么it?有人可以用小例解释吗?
我正在学习单元测试,我试图解决以下问题:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for zfcUserAuthentication
Run Code Online (Sandbox Code Playgroud)
...使用给出的唯一答案:
所以我的setUp函数看起来一样.不幸的是,我收到错误消息:
Zend\Mvc\Exception\InvalidPluginException: Plugin of type Mock_ZfcUserAuthentication_868bf824 is invalid; must implement Zend\Mvc\Controller\Plugin\PluginInterface
Run Code Online (Sandbox Code Playgroud)
它是由代码的这一部分引起的(在我的代码中以相同的方式分开):
$this -> controller->getPluginManager()
->setService('zfcUserAuthentication', $authMock); // Error refers to this line.
Run Code Online (Sandbox Code Playgroud)
$ authMock对象显然没有实现plugininterface,我需要实现它来传递到setService.
$ authMock是不是要通过那里,因为它用于单元测试?我应该使用不同的(面向单元测试的)setService方法吗?
我需要一种方法来处理登录到我的应用程序,或者我的单元测试毫无意义.
谢谢你的建议.
===编辑(11/02/2013)===
我想专注于这一部分以澄清,因为我认为这是问题领域:
// Getting mock of authentication object, which is used as a plugin.
$authMock = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication');
// Some expectations of the authentication service.
$authMock -> expects($this->any())
-> method('hasIdentity')
-> will($this->returnValue(true));
$authMock -> expects($this->any())
-> method('getIdentity')
-> …Run Code Online (Sandbox Code Playgroud) 我在zend框架2中使用doctrine 2.下面是我的实体文件.问题是,当我尝试使用时验证模式,
./vendor/bin/doctrine-module orm:validate-schema
Run Code Online (Sandbox Code Playgroud)
命令.
我收到了错误,
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'database.opportunitycriteria' already exists.
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
namespace Administration\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* OpportunityCriteria
*
* @ORM\Table(name="OpportunityCriteria")
* @ORM\Entity
*/
class Criteria
{
/**
* @var integer
* @ORM\Id
* @ORM\Column(name="criteria_id", type="integer", nullable=false)
*/
private $criteria_id;
/**
* @var string
*
* @ORM\Column(name="description", type="string", nullable=false)
*/
private $description;
}
Run Code Online (Sandbox Code Playgroud)
和适当的getter和setter方法..
我知道这个问题可能在这里和互联网上出现过几次.但我仍然觉得有人想要进入框架世界并不清楚.我已经按照这些链接Rob Allens Tutorial,ZF Quick Tutorial.
但有些我觉得安装部分不太清楚.我的Windows系统基本上是Vista,安装了最新版本的XAMPP.我从这个链接ZFSkeletonApp下载了最新版本的ZFSkeletonApplication ,提取了骨架内容,将文件夹重命名为zendframework并将其移动到xampp文件夹,即现在ZF骨架在c:\ xampp\zendframework中.
所以直到这里一切看起来都清晰简单,从这里我可以看出配置如何丢失.有人可以从这里详细说明如何安装Zf并使其工作,如包含路径,.htaccess文件等的更改.请记住,我有带XAMPP的窗户.如果有人可以指导我完成这个设置,那将会很有帮助.
PS如果能够通过路径组成的示例提供有关我需要做出的更改的信息会很好,这样我就不会丢失,例如你可以在这里找到.htaccess文件(ex pathname),更改.htaccess文件应该是这样的.
谢谢
我正在尝试使用路由创建带有查询字符串的URL,如下所示:
$this->url('users') -> /users
$this->url('users', ['sort' => 'desc']) -> /users?sort=desc
Run Code Online (Sandbox Code Playgroud)
然而,这似乎不起作用(第二个助手实际输出/users).根据这个非官方的,过时的文档,曾经有一种方法可以通过附加/query到路由名称来实现,但是这会给出一个路由未找到的异常.
可以使用当前的url帮助程序完成吗?
当我使用composer更新zf-commons/zfc-admin时,它会给出一个RuntimeException错误
[RuntimeException]
/var/www/site2.com/vendor/zf-commons/zfc
-admin中缺少.git目录,有关详细信息,请参阅http://getcomposer.org/commit-deps
由于此错误,我无法更新框架中的任何其他模块.
zend-framework2 ×10
php ×5
zend-form2 ×2
composer-php ×1
dgrid ×1
doctrine-orm ×1
dojo ×1
forms ×1
git ×1
label ×1
layout ×1
phpunit ×1
windows ×1
xampp ×1
zend-route ×1
zend-router ×1
zfcuser ×1