我正在尝试使用Common包中的doctrine缓存,但我无法使用一对多,多对一的协议.我稍后会解释我想做什么.
我的配置:
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
'result_cache' => 'filesystem',
'hydration_cache' => 'filesystem',
)
),
Run Code Online (Sandbox Code Playgroud)
我的实体
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var string
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100, nullable=false)
*/
protected $name;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="childrenId", fetch="EAGER")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
protected $parentId;
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parentId", fetch="EAGER")
*/
protected $childrenId;
}
Run Code Online (Sandbox Code Playgroud)
我的DQL
$result = …
Run Code Online (Sandbox Code Playgroud) 我有Zend Framework 2中内置的应用程序.我想设置cron作业来更新我的产品.我知道这样的脚本应该从公共文件夹外部运行,但不幸的是我在cron中的脚本需要使用框架文件.
我怎样才能做到这一点?
我想出的唯一方法是从公共文件夹外部运行脚本,然后添加一些哈希或密码并重定向到
www.domain.com/cron/test
Run Code Online (Sandbox Code Playgroud)
所以我将拥有所有框架功能.
它会安全吗?也许还有另一种方式?
当我在搜索有关在ZF2中设置cookie的信息时,我发现了Zend Framework 2 - Cookie Concept这个主题,但似乎该主题中包含的信息已经过时.
我试过以下代码:
public function indexAction()
{
$request = $this->getRequest()->getHeaders()->get('Set-Cookie')->foo = 'bar;
$response = $this->getResponse()->getCookie()->baz = 'test';
var_dump($_COOKIE);
...
return new ViewModel();
}
Run Code Online (Sandbox Code Playgroud)
两行输出警告:
Warning: Creating default object from empty value
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
public function indexAction()
{
$cookie = new SetCookie('test', 'value', 60*60*24); // Zend\Http\Header\SetCookie instance
$header = new Cookie(); // Zend\Http\Cookies instance
$header->addCookie($cookie);
...
return new ViewModel();
}
Run Code Online (Sandbox Code Playgroud)
它没有返回任何错误或警告,一切似乎都没问题,但是当我尝试var_dump($ _ COOKIE)时它仍然显示为null.
是的,我的浏览器启用了cookie.
我刚刚开始在Zend中使用PHPUnit,并且无需帮助弄清楚这些测试应该如何工作.
如果我没有传递任何POST参数,我想测试表单是否返回任何错误消息.
问题是我的表单中的一个字段是使用Doctrine的 DoctrineModule\Form\Element\ObjectSelect
...
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'user',
'attributes' => array(
'id' => 'user-label',
),
'options' => array(
'object_manager' => $em,
'target_class' => 'Application\Entity\User',
'property' => 'username',
'label' => 'User:',
'display_empty_item' => true,
'empty_item_label' => '---',
'label_generator' => function($entity) {
return $entity->getUsername();
},
),
));
...
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Fatal error: Call to a member function getIdentifierFieldNames() on null
我尝试使用模拟对象覆盖此字段,但是Zend不允许objects
输入type
,只是类名(string
),因此此代码不起作用:
public function testIfFormIsValid()
{
$objectSelect = $this->getMockBuilder('DoctrineModule\Form\Element\ObjectSelect')
->disableOriginalConstructor()
->getMock();
$objectSelect->expects($this->any())
->method('getValueOptions')
->will($this->returnValue(array())); …
Run Code Online (Sandbox Code Playgroud) 我试图用PHP app和node.js一起运行nginx(这部分工作正常).另外我想将socket.io添加到此设置中,但不幸的是我无法在客户端和服务器之间建立连接(看起来像连接超时?).
server.js
var app = require("http"),
redis = require("redis"),
io = require('socket.io')(app);
io.sockets.on( 'connection', function( client ) {
console.log( "New client !" );
io.sockets.emit('msg', { msg: 'Foo bar' } );
});
app.createServer().listen(3000);
console.log("Server running at 127.0.0.1:3000");
Run Code Online (Sandbox Code Playgroud)
client.js
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<!-- <script src="/js/socket.io-client/socket.io.js" type="text/javascript"></script>-->
<script>
var socket = io.connect('http://localhost:3000');
socket.on('msg', function(msg) {
alert('News from server: ' + msg.msg);
});
</script>
Run Code Online (Sandbox Code Playgroud)
(我尝试过很多url变种.有/无http,127.0.0.1:3000,myappp.dev等)
这是我目前的nginx配置
server {
listen *:80;
server_name myapp.dev www.myapp.dev;
client_max_body_size 1m;
root /var/www/public;
index index.html index.htm index.php;
access_log …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用REST API.我想检查HTTP缓存是否正常工作,但不幸的是我根本不工作.无论我做什么,它总是返回HTTP代码200,而它应该从我所知道的返回304.
这是我的PHP代码:
public function getList()
{
$this->addHeaders(array(
'Cache-Control' => 'public, must-revalidate, max-age=120',
'eTag' => 'xyz123',
));
$array = array(
'foo' => 'bar',
'nested' => array(
'lorem' => 'ipsum',
'dolor' => 'sit amet'
)
);
$this->addHeader('Content-Length', strlen(json_encode($array, true)));
return new JsonModel($array);
}
Run Code Online (Sandbox Code Playgroud)
响应/请求
ETag不会更改,因此除了第一个请求之外的请求应该从缓存中提供.我错了吗?
我正在关注这两篇文章:
我还检查了弱验证器 - Last-Modified但我遇到了同样的问题.浏览器在Request中发送正确的标头,但我仍然得到200响应
我的主页上有一个大尺寸图像(~6 MB)。这是一种地图。
我想将该图像存储在用户的浏览器中,即使他们关闭浏览器或重新启动电脑,是否有可能?如果重要的话,该图像会在 CSS 文件中使用。
我的主机带宽较小,因此我想在用户的浏览器上尽可能长时间地存储该图像,感谢您的任何提示。
我正在尝试使用composer将FirePHP添加到我的Zend Framework 2项目中,但是我收到了错误.
我的操作系统是Windows 7.
我尝试了以下方法使其工作:
我将以下代码添加到composer.json文件中:
"repositories": [{
"type": "vcs",
"url": "https://github.com/RobLoach/firephp-core"
}],
"require": {
"firephp/firephp-core": "dev-master" // Tried also: "firephp/firephp-core": "*"
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
[RuntimeException]
Failed to clone http://github.com/RobLoach/firephp-core.git, git was not found, check that it is installed and in your PATH env.
Run Code Online (Sandbox Code Playgroud)
我尝试在代码中添加到composer.json,这是我在firephp pull请求中找到的.:
"require": {
"firephp/firephp-core": "*"
}
Run Code Online (Sandbox Code Playgroud)
但它给了我上面发布的相同错误.作曲家对我来说是全新的.我找不到任何有用的教程,所以我不确定它是如何工作的,但我正在尽我所能熟悉它.
我希望有人可以告诉我我做错了什么.
谢谢.
编辑:感谢@Seldaek的帮助,我得到了它,但它删除了我的Zend库文件夹.
这是cmd的日志:
E:\xampp\htdocs\ZendSkeleton>php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing firephp/firephp-core (dev-master f60753a)
Cloning f60753a8dd7817e4da6bc73e0e717387a9a0866a
- Removing …
Run Code Online (Sandbox Code Playgroud) 我想在我的验证课中获得ServiceLocator.我尝试从Controller实例获取它,但它返回null.
MyValidation.php
namespace Register\Validator;
use Zend\Validator\AbstractValidator;
use Register\Controller\RegisterController;
class MyValidation extends AbstractValidator {
/*
code...
*/
function isValid($value)
{
$controller = new RegisterController();
$sm = $controller->getServiceLocator();
$tableGateway = $sm->get('Register\Model\RegisterTable');
$tableGateway->myValidationMethod($value);
}
Run Code Online (Sandbox Code Playgroud)
}
Module.php
public function getServiceConfig()
{
return array(
'factories' => array(
'Register\Model\RegisterTable' => function($sm) {
$tableGateway = $sm->get('RegisterTableGateway');
$table = new RegisterTable($tableGateway);
return $table;
},
'RegisterTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new RegisterUser());
return new TableGateway('table-name', $dbAdapter, null, $resultSetPrototype);
},
),
);
} …
Run Code Online (Sandbox Code Playgroud) php ×5
caching ×2
composer-php ×1
cookies ×1
cron ×1
doctrine-orm ×1
firephp ×1
html ×1
http ×1
http-caching ×1
http-headers ×1
nginx ×1
node.js ×1
phpunit ×1
socket.io ×1
symfony ×1
tablegateway ×1