1

現在、$this->paginate() で包含可能を使用しようとしていますが、結果セットで余分なテーブルを取得できません。結果セットに MediaItem と MediaCollectionItem があることを期待しています。

以下は、インデックスアクション用のコントローラーコードです

App::uses('MediaAppController', 'Media.Controller');
    class ItemsController extends MediaAppController {

        var $uses = array("Media.MediaItem", "Media.MediaCollection");
        var $components = array("Media.MediaRender","Media.TimThumb");
        var $helpers = array("Media.MediaRender");

        var $mediaItemDetails = null;

        var $paginate = array('limit' => 15, 'contain' => array('Media.MediaCollectionItem'));

        function beforeFilter() {
            parent::beforeFilter();
            $this -> Auth -> allow("resizeImage");

        }

        function admin_index() {

            $this -> request -> data = $this->paginate('MediaItem');

            debug($this -> request -> data);

            // Get images group
            $filters = $this -> MediaRender -> getCollectionFilterTypes(array("images"));

            $renderImageTypes = array_keys($filters["images"]["extensions"]);

            $this -> set(compact("renderImageTypes"));

        } 

以下は、すべての関係を持つ MediaItem モデルです

App::uses('MediaAppModel', 'Media.Model');
class MediaItem extends MediaAppModel {

/**
 * Display field
 *
 * @var string
 */
    var $displayField = 'name';


    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */
    var $hasMany = array(
        'MediaCollectionItem' => array(
            'className' => 'Media.MediaCollectionItem',
            'foreignKey' => 'media_item_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'MediaCollection' => array(
            'className' => 'Media.MediaCollection',
            'foreignKey' => 'media_item_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'media_item_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );

}

以下は、すべての関係を持つ MediaCollectionItem モデルです

    App::uses('MediaAppModel', 'Media.Model');
class MediaCollectionItem extends MediaAppModel {

/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'title';

    public $order = array("MediaCollectionItem.sort_order ASC");

    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'MediaCollection' => array(
            'className' => 'Media.MediaCollection',
            'foreignKey' => 'media_collection_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'MediaItem' => array(
            'className' => 'Media.MediaItem',
            'foreignKey' => 'media_item_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
}

プラグイン AppModel

class MediaAppModel extends AppModel {
        public $actsAs = array("Containable");
}

現在の実績例

array(
    (int) 0 => array(
        'MediaItem' => array(
            'id' => '1098',
            'name' => 'custom',
            'extension' => 'css',
            'file_size' => '0',
            'mime_type' => 'application/x-empty',
            'filename' => '2538984824fdb12ed8c8151.31598776.custom',
            'created' => '2012-06-15 11:48:13',
            'modified' => '2012-06-15 11:48:13',
            'remote_url' => null
        )
    ),
    (int) 1 => array(
        'MediaItem' => array(
            'id' => '1099',
            'name' => 'style',
            'extension' => 'css',
            'file_size' => '39002',
            'mime_type' => 'text/plain; charset=us-ascii',
            'filename' => '867449124fdb12fa1d3d11.81854984.style',
            'created' => '2012-06-15 11:48:26',
            'modified' => '2012-06-15 11:49:08',
            'remote_url' => null
        )
    ),

コントローラー内の MediaItem モデルのデバッグ

object(AppModel) {
    useDbConfig => 'default'
    useTable => 'media_items'
    id => false
    data => array()
    schemaName => 'cbsroxy_cms'
    table => 'media_items'
    primaryKey => 'id'
    validate => array()
    validationErrors => array()
    validationDomain => null
    name => 'MediaItem'
    alias => 'MediaItem'
    tableToModel => array(
        'media_items' => 'MediaItem'
    )
    cacheQueries => false
    belongsTo => array()
    hasOne => array()
    hasMany => array()
    hasAndBelongsToMany => array()
    actsAs => null
    Behaviors => object(BehaviorCollection) {
        modelName => 'MediaItem'
        defaultPriority => (int) 10
    }
    whitelist => array()
    cacheSources => true
    findQueryType => null
    recursive => (int) 1
    order => null
    virtualFields => array()
    __backAssociation => array()
    __backInnerAssociation => array()
    __backOriginalAssociation => array()
    __backContainableAssociation => array()
    findMethods => array(
        'all' => true,
        'first' => true,
        'count' => true,
        'neighbors' => true,
        'list' => true,
        'threaded' => true
    )
    tablePrefix => ''
4

1 に答える 1

0

私は今、それを機能させることができました。プラグイン モデルのプレフィックスを「media_」に設定し、クラス名を「Media.Item」にして、「$this->Item->find()」を呼び出して、包含可能な動作を機能させる必要がありました。

于 2014-02-05T13:32:34.300 に答える