2014-05-12 17 views
0

我在Laravel 4.1建立模塊化系統。但是我有一個模塊模型的問題。這是我的系統方案。Laravel無法看到模塊的型號在同級車

app/modules 
app/modules/product/ 
app/modules/controllers/ProductController.php 
app/modules/controllers/CatalogController.php 
app/modules/models/CatalogProductImage.php 
app/modules/models/ProductCatalog.php 
app/modules/models/CatalogProductImage.php 

的問題是,我ProductCatalog模型不能看到我的CatalogProductImage模型,因此它給了我下面的錯誤:

Symfony \ Component \ Debug \ Exception \ FatalErrorException 
Class 'CatalogProductImage' not found 

我不知道原因。這裏談到的代碼:

ProductCatalog.php

<?php namespace App\Modules\Product\Models; 

use Illuminate\Auth\UserInterface; 
use Illuminate\Auth\Reminders\RemindableInterface; 
use Eloquent; 
use App\Modules\Product\Models\CatalogProductImage as CatalogProductImage; 

class ProductCatalog extends Eloquent { 
    protected $table   = 'catalog'; 
    protected $primaryKey = 'catalogId'; 
    protected $connection = 'mysql2'; 
    public $timestamps  = FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller 

    public function category() { 
     return $this->hasOne('CatalogCategory', 'catalogCategoryId', 'catalogCategoryId'); 
    } 

    public function images() { 
     return $this->hasMany('CatalogProductImage', 'catalogId'); 
    } 
} 

CatalogProductImage.php

<?php namespace App\Modules\Product\Models; 

use Illuminate\Auth\UserInterface; 
use Illuminate\Auth\Reminders\RemindableInterface; 
use Eloquent; 

class CatalogProductImage extends Eloquent { 

    protected $table   = 'catalog_image'; 
     protected $primaryKey = 'catalogImageId'; 
    protected $connection = 'mysql2'; 
     public $timestamps  = FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller 

    public function catalog() { 
     return $this->hasMany('ProductCatalog', 'catalogId'); 
    } 

} 

編輯:我改變了CatalogProductImage從模塊...到App \模塊...但仍沒有按沒有工作。

+0

試舉全路徑應用程序\模塊\產品\型號\ CatalogProductImage – umefarooq

+0

我嘗試了兩種,但它沒有工作:( –

+0

你有沒有問題一個'composer dump-autoload'' –

回答

0

好我發現了這個問題。我應該在hasMany函數中定義完整路徑。像:

return $this->hasMany('App/Modules/Product/Models/CatalogProductImage', 'catalogId'); 

不喜歡這樣的:

return $this->hasMany('CatalogProductImage', 'catalogId'); 
0

你有沒有在composer.json添加的目錄

"autoload": { 
    "classmap": [ 
     "app/modules", 
     "app/commands", 
     "app/controllers", 
     "app/models", 
     "app/database/migrations", 
     "app/database/seeds", 
     "app/tests/TestCase.php" 
    ] 
}, 

然後composer dump-autoload

您也可以嘗試在設置,應用程序/啓動/ global.php

ClassLoader::addDirectories(array(
+0

是的,我不知道,這不是答案。 –