Magento 1.7 - getModel in script outside web application fails

后端 未结 7 1838
猫巷女王i
猫巷女王i 2021-01-17 04:31

    
        
            Starmall_Shipment_Model
            s         


        
相关标签:
7条回答
  • 2021-01-17 04:54

    You should define your model under <global> tag in config.xml like

    <global>    
        <models>
            <starmall_shipment>
                <class>Starmall_Shipment_Model</class>
                <resourceModel>starmall_shipment_mysql4</resourceModel>
            </starmall_shipment>
    
            <starmall_shipment_mysql4>
                <class>Starmall_Shipment_Model_Mysql4</class>
                <entities>
                    <shipment>
                        <table>starmall_shipment</table>
                    </shipment>             
                </entities>
            </starmall_shipment_mysql4>
        </models>
    </global>   
    

    because you are accessing if from outside the module.

    0 讨论(0)
  • 2021-01-17 04:56

    Have a look how Magento cron works - it works as standalone script also (cron.php) and copy-paste code to your custom module. Main things:

     require 'app/Mage.php';
     ...
     Mage::getConfig()->init()
    

    Also it seems like modules not loaded Try to add after init config:

    Mage::getConfig()->loadModules();
    
    0 讨论(0)
  • 2021-01-17 04:56

    It is prepending Mage because it is one of the core directories.. In my server, I see /var/www/app/code/core/Mage/ as a navigable path.

    Put your standalone scripts in your mage base dir, and use the following code at the "beginning"

    <?php
       require_once 'app/Mage.php';
       Mage::app('admin'); 
    

    Hopefully this will be enough to get your magento up and running, then you can figure out why the paths aren't working the way you expect.

    0 讨论(0)
  • 2021-01-17 05:10

    CarComp is write, after adding Mage::app('admin');
    the Mage::getConfig()->init() working like a charm.

    0 讨论(0)
  • 2021-01-17 05:12

    Why does it prepend Mage in front of the model? What can be wrong in my config?

    To see, where this is happening, look at Mage_Core_Model_Config::getGroupedClassName():

        if (empty($className)) {
            if (!empty($config)) {
                $className = $config->getClassName();
            }
            if (empty($className)) {
                $className = 'mage_'.$group.'_'.$groupType;
            }
            if (!empty($class)) {
                $className .= '_'.$class;
            }
            $className = uc_words($className);
        }
    

    This can mean one of two things:

    1. The $config node was not found (global/models/starmall_shipment)
    2. The node has no class or model child or it is empty

    In your case it looks like (1), so the question remains, why is your config not loaded. You assured that the config itself is correct, so the problem must be that the module is not loaded.

    Can you post your module declaration file from app/etc/modules?

    0 讨论(0)
  • 2021-01-17 05:12

    Check whether compilation mode is enabled in your store(System->Tools->Compilation).If yes then re-run compilation process

    0 讨论(0)
提交回复
热议问题