2011-01-11 10 views
0

我正在使用Zend和Doctrine2,我需要使用相同的結構創建一些cronjob。問題是,當我試圖從與另一個Model關係的Model中獲取存儲庫時,出現錯誤(僅在命令行中,如果我這樣做,在網站中工作正常)。Zend&Doctrine2:與命令行腳本中的代理錯誤

這是我在命令行出現錯誤:

致命錯誤:類 '代理\ Model_MediaPresetsProxy' 未找到在C:\ PHP \庫\原則\ ORM \代理\ ProxyFactory.php上線92

我有這個文件夾中的代理/應用/模型/代理/和文件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 /隊列/ 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

在Model_MediaQueue中,您導入ArrayCollection,但仍然在構造函數中使用FQN:P – Cobby 2011-01-12 23:12:27

+0

hehe ..謝謝..這是我的第一個模型,我沒有注意到該線仍然存在。:) – SERPRO 2011-01-13 13:15:46

回答

0

過了一段時間,我發現自己的解決方案。

的問題是,我創建了2個不同的環境:發展CLDEV(命令行開發)

和我getEntityManager()函數曾與

[...] 
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development')); 
[...] 

所以,我線將其替換爲

[...] 
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development' || APPLICATION_ENV == 'cldev')); 
[...] 

並且問題解決了。希望它能在未來幫助別人。