我遇到配置问题或magento从不运行我的模块的sql install / update脚本的其他问题!
我使用的是magento-1.4.1.0
这是我的结构文件夹和文件:
\app\code\local\RN\ShortUrl
\app\code\local\RN\ShortUrl\Block\ShortUrl.php
\app\code\local\RN\ShortUrl\controllers\IndexController.php
\app\code\local\RN\ShortUrl\controllers\UController.php
\app\code\local\RN\ShortUrl\etc\config.xml
\app\code\local\RN\ShortUrl\Helper\Url.php
\app\code\local\RN\ShortUrl\Model\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl\Collection.php
\app\code\local\RN\ShortUrl\Model
\app\code\local\RN\ShortUrl\Model\Mysql4
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl
\app\code\local\RN\ShortUrl\sql\rn_shorturl_setup\mysql4-install-0.1.0.php
以下是\app\etc\modules\RN_ShortUrl.xml
的内容:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<RN_ShortUrl>
<active>true</active>
<codePool>local</codePool>
</RN_ShortUrl>
</modules>
</config>
以下是\app\code\local\RN\ShortUrl\etc\config.xml
的内容:
<?xml version="1.0"?>
<config>
<modules>
<RN_ShortUrl>
<version>0.1.0</version>
</RN_ShortUrl>
</modules>
<frontend>
<routers>
<shorturl>
<use>standard</use>
<args>
<module>RN_ShortUrl</module>
<frontName>shorturl</frontName>
</args>
</shorturl>
</routers>
<layout>
<updates>
<shorturl>
<file>shorturl.xml</file>
</shorturl>
</updates>
</layout>
</frontend>
<global>
<blocks>
<rn_shorturl>
<class>RN_ShortUrl_Block</class>
</rn_shorturl>
</blocks>
<rewrite>
<rn_shorturl>
<from>#^/u/(.*)#</from>
<to>/shorturl/u/redirect/key/$1</to>
</rn_shorturl>
</rewrite>
<models>
<shorturl>
<class>RN_ShortUrl_Model</class>
<resourceModel>shorturl_mysql4</resourceModel>
</shorturl>
<shorturl_mysql4>
<class>RN_ShortUrl_Model_Mysql4</class>
<entities>
<shorturl>
<table>shorturl</table>
</shorturl>
</entities>
</shorturl_mysql4>
</models>
<resources>
<shorturl_setup>
<setup>
<module>RN_ShortUrl</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</shorturl_setup>
<shorturl_write>
<connection>
<use>core_write</use>
</connection>
</shorturl_write>
<shorturl_read>
<connection>
<use>core_read</use>
</connection>
</shorturl_read>
</resources>
<helpers>
<shorturl>
<class>RN_ShortUrl_Helper</class>
</shorturl>
</helpers>
</global>
这是我的安装SQL脚本:
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {$this->getTable('shorturl')};
CREATE TABLE {$this->getTable('shorturl')} (
`shorturl_id` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`shorted_key` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
`long_url` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`shorturl_id`),
INDEX (shorted_key),
INDEX (long_url)
)ENGINE=InnoDB CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';"
);
/* right before this */
$installer->endSetup();
我试图更改模块的版本并创建了升级脚本“mysql4-upgrade-1.0-1.1.php”,但仍然无效,但我可以运行我的模块。
除了我要问的问题外,它正在发挥作用。
提前致谢,
Rithy
答案 0 :(得分:4)
我注意到,当您更改版本号时,您创建了1.0-1.1的升级版,但您的版本实际上是0.1.0。这可以解释为什么它没有“升级”。您可能希望完全从核心资源中删除该行,并让它在下一页加载时“重新安装”。
或者,修改您的脚本,使其标记为从0.1.0-0.1.1升级。
答案 1 :(得分:3)
好的,现在我可以解决这个问题!
\应用\代码\本地\ RN \ SHORTURL \模型\ ShortUrl.php
public function removeShortedUrlModule()
{
$sql = "DELETE FROM `core_resource`
WHERE `code`='shorturl_setup';";
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
try {
$connection->query($sql);
die('deleted module in core_resource!');
} catch (Exception $e){
echo $e->getMessage();
}
}
2。更改文件夹名称\ app \ code \ local \ RN \ ShortUrl \ sql \ rn_shorturl_setup \
到\ app \ code \ local \ RN \ ShortUrl \ sql \ shorturl_setup \
最后我把它吹了! CHEER!