Magento example of an instantiated object in a CSV table upload

Source: Internet
Author: User

app\code\core\mage\dataflow\model\convert\parser\csv.php

The file is a background upload csv, inserted into the Dataflow_batch_import relay table code, has the following code snippet

1. $batchModel = $this->getbatchmodel ();

2. $batchModel->setparams ($this->getvars ())
->setadapter ($adapterName)
->save ();

Looking down from above,

The first line $this->getbatchmodel ();

Find the corresponding file

app\code\core\mage\dataflow\model\convert\parser\abstract.php

/**
* Retrieve Batch Model Singleton
*
* @return Mage_dataflow_model_batch
*/
Public Function Getbatchmodel ()
{
if (Is_null ($this->_batch)) {
$this->_batch = Mage::getsingleton (' Dataflow/batch ');
}
return $this->_batch;
}

Call the Mage::getsingleton method, and then continue to find the corresponding class

app\mage.php

/**
* Retrieve Model Object Singleton
*
* @param string $modelClass
* @param array $arguments
* @return Mage_core_model_abstract
*/
public static function Getsingleton ($modelClass = ", array $arguments =array ())
{
$registryKey = ' _singleton/'. $modelClass;
if (!self::registry ($registryKey)) {
Self::register ($registryKey, Self::getmodel ($modelClass, $arguments));
}
Return Self::registry ($registryKey);
}

The discovery will eventually call this class in the Getmodel () method

public static function Getmodel ($modelClass = ", $arguments = Array ())
{
Return Self::getconfig ()->getmodelinstance ($modelClass, $arguments);
}

Call this class GetConfig ()

/**
* Retrieve a config instance
*
* @return Mage_core_model_config
*/
public static function GetConfig ()
{
return self::$_config;
}

Returns an object of Mage_core_model_config, and calls Getmodelinstance ()

The corresponding file is: app\code\core\mage\core\model\config.php

/**
* Get Model class instance.
*
* Example:
* $config->getmodelinstance (' catalog/product ')
*
* would instantiate mage_catalog_model_mysql4_product
*
* @param string $modelClass
* @param array|object $constructArguments
* @return Mage_core_model_abstract|false
*/
Public Function getmodelinstance ($modelClass = ", $constructArguments =array ())
{
$className = $this->getmodelclassname ($modelClass);
if (class_exists ($className)) {
Varien_profiler::start (' core::create_object_of:: '. $className);
$obj = new $className ($constructArguments);
Varien_profiler::stop (' core::create_object_of:: '. $className);
return $obj;
} else {
return false;
}
}

Will determine if the class exists, and the new one will not exist.

The passed parameter is Dataflow/batch

Will call Getmodelclassname to determine if there is a

Public Function Getmodelclassname ($modelClass)
{
$modelClass = Trim ($modelClass);
if (Strpos ($modelClass, '/') ===false) {
return $modelClass;
}
return $this->getgroupedclassname (' model ', $modelClass);
}

You can see that if there is a slash, it means that this class is not instantiated and will be new

Return to Mage_dataflow_model_batch class

At this point the first line of code ends and the corresponding object is obtained

The second line calls $batchmodel->setparams ()

Apparently it's going to go to the app\code\core\mage\dataflow\model\batch.php file.

/**
* Set Additional params
* Automatic Convert to serialize data
*
* @param mixed $data
* @return Mage_dataflow_model_batch_abstract
*/
Public Function SetParams ($data)
{
$this->setdata (' params ', serialize ($data));
return $this;
}

Discovery Call SetData () method

This class does not, go to his father's class to find

Class Mage_dataflow_model_batch extends Mage_core_model_abstract

app\code\core\mage\core\model\abstract.php

Found no, he inherited the

Abstract class Mage_core_model_abstract extends Varien_object

Find the corresponding core class

lib\varien\object.php

Found it

/**
* Overwrite data in the object.
*
* $key can be string or array.
* If $key is string, the attribute value would be overwritten by $value
*
* If $key is an array, it'll overwrite all the data in the object.
*
* @param string|array $key
* @param mixed $value
* @return Varien_object
*/
Public Function SetData ($key, $value =null)
{
$this->_hasdatachanges = true;
if (Is_array ($key)) {
$this->_data = $key;
$this->_addfullnames ();
} else {
$this->_data[$key] = $value;
if (Isset ($this->_syncfieldsmap[$key])) {
$fullFieldName = $this->_syncfieldsmap[$key];
$this->_data[$fullFieldName] = $value;
}
}
return $this;
}

Magento example of an instantiated object in a CSV table upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.