I'm using the standard loader function at the moment:
Code: Select all
$this->load->model('setting/setting');
Thanks for any help in advance!...
Code: Select all
$this->load->model('setting/setting');
Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Code: Select all
public function adminmodel($model) {
$admin_dir = DIR_SYSTEM;
$admin_dir = str_replace('system/','admin/',$admin_dir);
$file = $admin_dir . 'model/' . $model . '.php';
//$file = DIR_APPLICATION . '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();
}
}
Code: Select all
// Extreme example to illustrate the danger ...
require('admin/model/sale/customer.php');
$adminCustomerModel = new ModelSaleCustomer( $this->registry );
$adminCustomerModel->deleteCustomer( 123 );
Code: Select all
private function load_model($model) {
require('catalog/model/'.$model.'.php');
$model_path = 'model_'.str_replace('/', '_', $model);
$model_name = $this->create_model_name($model);
$this->$model_path = new $model_name( $this->registry );
}
private function create_model_name($model) {
$m_expl = explode('/', $model);
foreach($m_expl as $m) {
$m_UC[] = ucfirst($m);
}
return 'Model'.implode('', $m_UC);
}
Code: Select all
$this->load_model('account/customer');
$customer = $this->model_account_customer->getCustomer(78);
No, none of this is nice.justinv wrote: ↑Fri Dec 16, 2011 9:46 amYou are right, I suppose, there is quite a lot of duplication in code based on the admin and catalog being separate. It is nice though, because some functions are the same in admin and catalog, but have different results. For example, getProducts in admin returns all products so you can edit them, whereas in the frontend it gets them to display customers. Therefore one getProducts returns all products, the other only returns products with status = 1 (enabled).
Little differences like this make it nice to have them separate, and you can just copy the functions you need into the right file if you want to use them.
Users browsing this forum: No registered users and 271 guests