从管理员端使用前端模型功能 [英] Use front side model function from admin side

查看:79
本文介绍了从管理员端使用前端模型功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencart 版本1.5.1.3 . 在一个阶段,我想在管理端控制器文件中使用前端模型功能.

I'm working on opencart Version 1.5.1.3. At one stage i want to use front side model function in the admin side controller file.

有人可以帮助我吗?会感激的.

Can anyone please help me.? It would be appreciated.

推荐答案

我知道已经很晚了,但可能对以后的工作很有用.
只需将功能添加到/system/engine/loader.php.但是您可能知道直接这样做可能会在将来对您造成伤害.因此,通过vqmod进行操作.我会告诉你如何:

I know it's late but maybe useful for future works.
Simply you can add a function to your /system/engine/loader.php. But you may know doing this directly may harm you in the future. So do it through vqmod. I'll tell you how:

<?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模型使用此:

You can put this code in file name your_own_chosen_name.xml and place it in /vqmod/xml.
Now for using e.g. shipping/flat model of catalog directory in admin use this:

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

这篇关于从管理员端使用前端模型功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆