Best place to add URL Rewrite during extension install
سؤال
I am working on an extension right now that needs to have a URL rewrite setup when it is installed. Is the best place to do this in a data install script? If not, where should this be done?
المحلول
It's not a big difference.
From what I saw, how Magento does, if you plan to use direct inserts, place your script in the sql
install script.
If you plan to use models and the internal model API you should put it in the data
folder.
Here are some examples. In the customer module in sql/.../install-1.6.0.0.php
there is this:
$installer->getConnection()->insertForce($installer->getTable('customer/customer_group'), array(
'customer_group_id' => 0,
'customer_group_code' => 'NOT LOGGED IN',
'tax_class_id' => 3
));
In the catalog model there is this in data/.../install-1.6.0.0.php
:
Mage::getModel('catalog/category')
->load(1)
->setId(1)
->setStoreId(0)
->setPath(1)
->setLevel(0)
->setPosition(0)
->setChildrenCount(0)
->setName('Root Catalog')
->setInitialSetupFlag(true)
->save();
[EDIT]
I forgot one thing. The upgrade scripts are executed when the modules are initialized and the data upgrades are executed a little later after the current store is initialized, after the full config is loaded, the translates are already loaded and others.
Based on this you can see what works for you best.