zoukankan      html  css  js  c++  java
  • Magento 创建新的数据实体 model 、 resource 和 collection 文件


    一、创建model文件
    class Bestbuy_PrepaidCard_Model_Used extends Mage_Core_Model_Abstract
    {
     
        protected function _construct()
        {
            $this->_init('prepaidcard/used');
        }
     
    }


    二、创建resource文件
    class Bestbuy_PrepaidCard_Model_Resource_Used extends Mage_Core_Model_Resource_Db_Abstract
    {
        /**
         * Initialize resource model
         *
         */
        protected function _construct()
        {
            $this->_init('prepaidcard/used', 'id');
        }
     
    }

    三、创建Collection文件
    class Bestbuy_PrepaidCard_Model_Resource_Used_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
    {
           public function _construct()
           {
                parent::_construct();
                $this->_init('prepaidcard/used', 'id');
           }
     
     
    }

    最后看一下三个文件的目录层次路径:


    只有这样,才能在代码中使用这样的语句来操作实体:
    //giftcard
    $giftcard_model = Mage::getModel('enterprise_giftcardaccount/history');
    $giftcard_info = $giftcard_model->getCollection()
    ->join(array('g' => 'giftcardaccount'),'main_table.giftcardaccount_id = g.giftcardaccount_id','*')
    ->addFieldToFilter('additional_info','订单 # '.$order_info->getData('increment_id').'.')->load();
    //prepaycard
    $prepaycard_model = Mage::getModel('prepaidcard/used');
    $prepaycard_info = $prepaycard_model->getCollection()
    ->addFieldToFilter('order_id',$this->getRequest()->getParam('order_id'))->load();

    print_r($prepaycard_info->getFirstItem()->getData());





  • 相关阅读:
    架构-缓存
    工具-Memcahce和Redis比较
    职业-把工作当作职业 or 事业?
    MySQL-查询结果缓存
    MySQL-SQL语句中SELECT语句的执行顺序
    getXXXPos()约定
    FBX BlendShape/Morph动画解析
    quick cocos2dx 3.x 配置win32工程
    cocos2dx 3.x fullPathForFilename及isFileExist在ios/mac下与win32下行为不同
    osX显示隐藏文件
  • 原文地址:https://www.cnblogs.com/caryfang/p/5110249.html
Copyright © 2011-2022 走看看