我正在使用Zend和Doctrine2,我需要使用相同的结构创建一些cronjobs。问题是,当我试图从与另一个模型有关系的模型中获取存储库时,我收到了一个错误(仅在命令行中,如果我这样做,网站中的工作正常)。
这是我在命令行中遇到的错误:
致命错误:第92行的c:\ php \ library \ Doctrine \ ORM \ Proxy \ ProxyFactory.php中找不到类'Proxy \ Model_MediaPresetsProxy'
我在此文件夹 / application / models / proxies / 中有代理,而文件Model_MediaPresetsProxy在该目录中
<?php
namespace Proxy;
/**
* THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE.
*/
class Model_MediaPresetsProxy extends \Model_MediaPresets implements \Doctrine\ORM\Proxy\Proxy
{
[...]
以下是我为 crons
创建的内容/crons/init.php
<?php
$time = microtime(true);
$memory = memory_get_usage();
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', 'cldev');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
defined('NL')
|| define('NL', "\n");
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();
// set bootstrap param
$bootstrap = $application->getBootstrap();
$front = $bootstrap->getResource('FrontController');
$front->setParam('bootstrap', $bootstrap);
register_shutdown_function('__shutdown');
function __shutdown()
{
global $time, $memory;
$endTime = microtime(true);
$endMemory = memory_get_usage();
echo '
Time [' . ($endTime - $time) . '] Memory [' . number_format(( $endMemory - $memory) / 1024) . 'Kb]
';
}
然后我创建了我的cronjob以测试一切正常
/crons/queue/processQueue.php
<?php
require realpath( dirname(__FILE__) . '/../init.php');
$paths = Helper_Media::getPaths();
$magick = new App_PhMagick();
$em = Zend_Registry::getInstance()->entityManager;
$queue = $em->getRepository('Model_MediaQueue')->findAll();
echo 'Items in the queue: ' . count($queue) . NL;
这就是我正在使用的模型
/application/models/MediaQueue.php
<?php
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="media_queue")
*/
class Model_MediaQueue
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $queue_id;
/**
* @ManyToOne(targetEntity="Model_MediaPresets")
* @JoinColumn(name="queue_preset_id", referencedColumnName="preset_id")
*/
private $media_preset;
/**
* @ManyToOne(targetEntity="Model_Sites", inversedBy="media_list")
* @JoinColumn(name="queue_site_id", referencedColumnName="site_id")
*/
private $media_site;
/**
* @Column(type="string")
*/
private $source_media_file;
/** @Column(type="integer") */
private $result_media_id;
/** @Column(type="integer") */
private $queue_status;
/** @Column(type="integer") */
private $queue_added;
/** @Column(type="integer") */
private $queue_processed;
public function __construct()
{
$this->media_preset = new \Doctrine\Common\Collections\ArrayCollection();
$this->media_site = new \Doctrine\Common\Collections\ArrayCollection();
}
[...]
}
/application/models/MediaPresets.php
<?php
/**
* @Entity
* @Table(name="media_presets")
*/
class Model_MediaPresets
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $preset_id;
/**
* @Column(name="preset_type", type="string", columnDefinition="enum('video', 'photo')")
*/
private $preset_type;
/** @Column(type="string") */
private $preset_name;
/** @Column(type="string") */
private $preset_formats_order;
/** @Column(type="integer") */
private $preset_size_w;
/** @Column(type="integer") */
private $preset_size_h;
/**
* @Column(name="preset_resize_method", type="string", columnDefinition="enum('Maintain', 'Stretch', 'Centre', 'Abort')")
*/
private $preset_resize_method;
/** @Column(type="string") */
private $preset_watermark;
/** @Column(type="string") */
private $preset_background;
}
任何线索?
非常感谢:)
答案 0 :(得分:0)
过了一段时间,我发现自己就是解决方案。
问题是我创建了两个不同的环境:开发和 CLDEV (命令行开发)
我的getEntityManager()函数有一行
[...]
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development'));
[...]
所以我用
替换了它[...]
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development' || APPLICATION_ENV == 'cldev'));
[...]
问题解决了。希望将来能帮助别人。