我正在尝试在我的实体类上使用Service Manager,但我不知道最好的方法.
在控制器上很容易,因为我们可以使用以下命令调用服务管理器:$ this-> getServiceLocator();
但是,在我的实体类中,即使我实现了ServiceLocatorAwareInterface,我也可以通过服务管理器来调用ServiceManager,因为我的实体类没有被调用:
那么最好的方法是什么:
1 - 从我的控制器2传递我的实体类中的serviceManager - 使用ServiceManager构建我的实体类3 - ...?
为了最好地理解我的问题,这是我的代码不起作用:
我的实体类:
class Demande extends ArraySerializable implements InputFilterAwareInterface {
/../
public function getUserTable() {
if (! $this->userTable) {
$sm = $this->getServiceLocator();//<== doesn't work !
$this->userTable = $sm->get ( 'Application\Model\UserTable' );
}
return $this->userTable;
}
Run Code Online (Sandbox Code Playgroud) 在Zend Framework 1中,有一个数据库适配器的quoteinto方法,可用于引用sql语句.
我想知道它在Zend Framework 2中的等价物吗?
我是Clojurescript的新手.我想知道如何创建html元素,以及如何使用clojurescript更改其属性.我似乎无法在网上找到很多相关信息.
在Zend Framework 1中,我有几个映射器从父Mapper类继承了setDbTable和getDbTable.
现在在ZF2中面对我需要模型中的服务管理器的问题,我不知道如何获取它:
class Mapper
{
protected $tableGateway;
protected $module = 'application';
public function setTableGateway($table)
{
if (is_string($table)) {
$class = $this->module . '\Model\DbTable\\' . ucfirst($table);
$sm = $this->getServiceLocator(); <= Fatal error: Call to undefined method Mapper::getServiceLocator()
$tableGateway = (class_exists($class)) ? $sm->get($class) : $sm->get(new TableGateway($table));
} else {
$tableGateway = $table;
}
if (!$tableGateway instanceof Zend\Db\TableGateway\AbstractTableGateway) {
throw new \Exception('Invalid table data gateway provided');
}
$this->tableGateway = $tableGateway;
return $this;
}
// more code
Run Code Online (Sandbox Code Playgroud)
这条线:
$sm = $this->getServiceLocator();
Run Code Online (Sandbox Code Playgroud)
给出致命错误: …
我无法弄清楚如何在使用composer进行自举时运行zf.php(Zend Framework 2 Tool).
首先我根据文档引导作曲家和zftool:
$ mkdir tmp && cd tmp
$ curl -s https://getcomposer.org/installer | php
$ ./composer.phar require zendframework/zftool:dev-master
Run Code Online (Sandbox Code Playgroud)
这到目前为止工作正常.
但是当我尝试运行zf.php时,我收到错误:
$ vendor/zendframework/zftool/zf.php
PHP Warning: require_once(/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php): failed to open stream: No such file or directory in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
Warning: require_once(/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php): failed to open stream: No such file or directory in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
PHP Fatal error: require_once(): Failed opening required '/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php' (include_path='.:/opt/local/lib/php') in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
Fatal error: require_once(): Failed opening required '/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php' (include_path='.:/opt/local/lib/php') …Run Code Online (Sandbox Code Playgroud) 如何在ZF2中获取应用程序布局中的当前(选定)模块名称?目的:我的应用程序布局包括zf2应用程序的主菜单,每次选择模块时,我都需要突出显示模块的菜单语音.此外,我需要设置正确的路线(网址,动作)时,使用此菜单.每个模块都有一个菜单语音:
<ul class="nav">
<?php foreach ($menu_modules as $mod):
$is_active = ($mod['name'] == $CURRENT_MODULE_NAME)?'selected':'';//GET MODULE NAME
?>
<!-- class="active" -->
<li><a href="#" <?php echo $is_active;?> ><?php echo $mod['title']; ?></a></li>
<?php endforeach; ?>
<li><a href="<?php echo $this->url('login/process', array('action'=>'logout')); ?>"><?php echo $this->translate('Logout') ?></a></li>
</ul>
<div class="row-fluid" id="main_container">
<?php echo $this->content; ?>
</div>
Run Code Online (Sandbox Code Playgroud) 我很难决定何时使用defrecord是正确的选择,更广泛地说,我在我的记录中使用的协议是否符合语义 clojure 和功能性。
在我当前的项目中,我正在构建一个游戏,该游戏具有不同类型的敌人,它们都具有相同的一组动作,这些动作可能以不同的方式实现。
来自 OOP 背景,我很想做这样的事情:
(defprotocol Enemy
"Defines base function of an Enemy"
(attack [this] "attack function"))
(extend-protocol Enemy
Orc
(attack [_] "Handles an orc attack")
Troll
(attack [_] "Handles a Troll attack"))
(defrecord Orc [health attackPower defense])
(defrecord Troll [health attackPower defense])
(def enemy (Orc. 1 20 3))
(def enemy2 (Troll. 1 20 3))
(println (attack enemy))
; handles an orc attack
(println (attack enemy2))
;handles a troll attack
Run Code Online (Sandbox Code Playgroud)
这从表面上看似乎是有道理的。我希望每个敌人总是有一种攻击方法,但实际实施应该能够因特定的敌人而异。使用extend-protocol我能够创建有效的调度方法,根据我的敌人而变化,我可以轻松添加新的敌人类型以及更改这些类型的功能。
我遇到的问题是为什么我应该在通用地图上使用记录?以上对我来说有点 OOP 的感觉,似乎我反对更实用的风格。所以,我的问题分为两个: …
我无法找到相当于此的东西
http://framework.zend.com/manual/1.12/en/zend.service.amazon.s3.html
在2.0版本的文档中.我还注意到2.0最小版本是2.5MB,而1.12最小版本是8.7MB,完整的1.12版本是~30MB.
我正在尝试将一个选择框添加到我的一个表单中(只是输入类型="文本"元素工作得很好)但我得到的只是一个没有标签的空选择框.所以这是我使用的代码:
Bla.php :: Bla-> getInputFilter()
$inputFilter->add($factory->createInput(array(
'type' => 'Zend\InputFilter\Select',
'name' => 'payment_type',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
Run Code Online (Sandbox Code Playgroud)
BlaForm.php :: BlaForm - > __ construct():
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'payment_type',
'options' => array(
'label' => 'Payment',
'value_options' => array(
0 => 'Nur Überweisung',
1 => 'Nur Paypal',
2 => 'Nur Barzahlung im Voraus',
),
),
'attributes' => array(
'value' => 0 //set selected to "Nur Überweisung"
)
));
Run Code Online (Sandbox Code Playgroud)
bla.php(查看)
<div class="control-group">
<?php
echo …Run Code Online (Sandbox Code Playgroud) 我正在学习ZF2,是否有可能ZF1中的Form装饰器模式已被删除?
我是否正确编写自己的视图助手,装饰我的表单?
php ×3
clojure ×1
frameworks ×1
html ×1
html-select ×1
javascript ×1
module ×1
quote ×1
router ×1
zend-form ×1