2012-05-29 19 views

回答

3

簡而言之,你不能。你需要做的是複製模型文件,如果其中一個相同的名稱不存在於管理端,或者將你需要的方法添加到管理端模型文件中

2

這就是我所做的: 你有一個模型目錄/模型/富/ frontbar.php 和另一個模型管理/模型/富/ adminbar.php

你要inlcude在adminbar.php frontbar.php,然後訪問frontbar的方法。

在adminbar.php

做這樣的事情:

<?php 
include_once __DIR__.'/../../../catalog/model/foo/frontbar.php'; 

class ModelFooAdminbar extends Model { 

    private $frontInstance; 
    public function fromFront() 
    { 
    if(!$this->frontInstance){ 
     $this->frontInstance = new ModelFooFrontbar($this->registry); 
    } 

    return $this->frontInstance; 
    } 
} 
?> 
在你的管理控制

然後做這樣的事情:

$this->load->model('foo/adminbar'); 
$this->data['someFrontData'] = $this->model_foo_adminbar->fromFront()->getSomeMethodInFrontbar(); 
4

我知道它的晚,但也許爲未來的工作有所幫助。
只需將您的功能添加到您的/system/engine/loader.php即可。但是你可能知道直接做這件事可能會在將來傷害你。所以通過vqmod。我會告訴你如何:

<?xml version="1.0" encoding="UTF-8"?> 
<modification> 
    <id>Loadin Catalog Models</id> 
    <version>1.0</version> 
    <vqmver>2.X</vqmver> 
    <author>Hossein Shahsahebi</author> 
    <file name="system/engine/loader.php"> 
     <operation info="Add function which I could access catalog models from admin"> 
      <search position="after"><![CDATA[ 
       protected $registry; 
      ]]></search> 
      <add><![CDATA[ 
       public function catalogModel($model) { 
        $file = DIR_CATALOG . 'model/' . $model . '.php'; 
        $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); 

        if (file_exists($file)) { 
         include_once($file); 

         $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); 
        } else { 
         trigger_error('Error: Could not load model ' . $model . '!'); 
         exit();    
        } 
       } 
      ]]></add> 
     </operation> 
    </file> 
</modification> 

你可以把文件名your_own_chosen_name.xml這個代碼,並把它放在/vqmod/xml
現在使用例如shipping/flat管理目錄目錄模型使用此:

$this->load->catalogModel('shipping/flat');