`
coolsooner
  • 浏览: 1341018 次
文章分类
社区版块
存档分类
最新评论

模块-----向数据库里面建表,写入数据,在读取数据

 
阅读更多

1

首先建立模块等一系列的文件,文件


2

etc/config.xml文件:

<?xml version="1.0"?>
<config>
<modules>
<RichardMason_Profile>
<version>1.10</version>
</RichardMason_Profile>
</modules>
<frontend>
<routers>
<profile>
<use>standard</use>
<args>
<module>RichardMason_Profile</module>
<frontName>profile</frontName>
</args>
</profile>
</routers>
<layout>
<updates>
<profile>
<file>profile.xml</file>
</profile>
</updates>
</layout>
</frontend>
<admin>
<routers>
<profile>
<use>admin</use>
<args>
<module>RichardMason_Profile</module>
<frontName>profile</frontName>
</args>
</profile>
<adminhtml>
<args>
<modules>
<RichardMason_Profile_Override before="Mage_Adminhtml">RichardMason_Profile_Override_Admin</RichardMason_Profile_Override>
</modules>
</args>
</adminhtml>


</routers>
</admin>
<adminhtml>
<menu>
<cms>
<children>
<news module="profile">
<title>News</title>
<sort_order>60</sort_order>
<action>profile/adminhtml_profile/news</action>
</news>
</children>
<children>
<testimonials module="profile">
<title>Testimonials</title>
<sort_order>61</sort_order>
<action>profile/adminhtml_profile/testimonials</action>
</testimonials>
</children>
<children>
<pressreleases module="profile">
<title>Press Releases</title>
<sort_order>62</sort_order>
<action>profile/adminhtml_profile/pressreleases</action>
</pressreleases>
</children>
<children>
<pressarticles module="profile">
<title>Press Articles</title>
<sort_order>63</sort_order>
<action>profile/adminhtml_profile/pressarticles</action>
</pressarticles>
</children>
</cms>
</menu>
<layout>
<updates>
<profile>
<file>profile.xml</file>
</profile>
</updates>
</layout>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<RichardMason_Profile>
<title>Profile Module</title>
<sort_order>10</sort_order>
</RichardMason_Profile>
</children>
</admin>
</resources>
</acl>

</adminhtml>
<global>
<models>
<profile>
<class>RichardMason_Profile_Model</class>
<resourceModel>profile_mysql4</resourceModel>
</profile>
<profile_mysql4>
<class>RichardMason_Profile_Model_Mysql4</class>
<entities>
<profile>
<table>profile</table>
</profile>
<profile_store>
<table>profile_store</table>
</profile_store>
</entities>
</profile_mysql4>
</models>
<resources>
<profile_setup>
<setup>
<module>RichardMason_Profile</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</profile_setup>
<profile_write>
<connection>
<use>core_write</use>
</connection>
</profile_write>
<profile_read>
<connection>
<use>core_read</use>
</connection>
</profile_read>
</resources>
<blocks>
<profile>
<class>RichardMason_Profile_Block</class>
</profile>
</blocks>
<helpers>
<profile>
<class>RichardMason_Profile_Helper</class>
</profile>
</helpers>
</global>
</config>
3

数据库文件

sql/profile_setup/mysql4-install-0.1.0.php


<?php

$installer = $this;

$installer->startSetup();

$installer->run("
DROP TABLE IF EXISTS `{$this->getTable('profile/profile')}`;
CREATE TABLE {$this->getTable('profile/profile')} (
`profile_id` smallint(6) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`thumbnail` varchar(255) NOT NULL,
`thumbnail_position` int(11) NOT NULL,
`picture` varchar(255) NOT NULL,
`file` varchar(255) NOT NULL,
`content_heading` varchar(255) NOT NULL DEFAULT '',
`content` mediumtext,
`meta_keywords` text NOT NULL,
`meta_description` text NOT NULL,
`creation_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`profile_id`),
KEY `identifier` (`content_heading`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `{$this->getTable('profile/profile_store')}`;
CREATE TABLE {$this->getTable('profile/profile_store')} (
`profile_id` smallint(6) NOT NULL,
`store_id` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`profile_id`,`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='CMS Profiles to Stores';

INSERT INTO `{$this->getTable('profile/profile')}` VALUES(1, 0, 'profile_examples/a5.jpg', 0, '', '', 'Example number 1', '<p><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </strong>Vestibulum et neque neque. Vestibulum id aliquet dolor. Etiam porta nulla ac odio pharetra venenatis euismod risus pulvinar. Donec tempor molestie faucibus. Aenean tempus, mi sed scelerisque tincidunt, nunc dui tristique dui, auctor auctor eros ipsum nec augue. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec consectetur erat quis nisi feugiat sit amet tempus mi aliquam. Nam mattis tortor eu lectus laoreet eu dignissim turpis rhoncus. Proin eu mi neque, et hendrerit tellus. Ut sed tortor nisi, id sodales lacus. Nulla ac elit tortor. Nulla eleifend turpis ac dui venenatis convallis. Etiam quis augue justo. Nunc eget tortor magna.</p>', 'keywords, keywords,...', 'this is a new', '2010-05-24 00:00:00', '2010-05-25 11:16:10', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(2, 0, 'profile_examples/a4.jpg', 0, '', '', 'Example number 2', '<p><strong>Donec vitae consequat nibh. </strong>Morbi blandit convallis rhoncus. Sed vel sapien urna, in rhoncus eros. In quis viverra urna. Donec bibendum nunc eget dolor scelerisque aliquam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse potenti. Proin dictum urna rutrum sapien pellentesque semper. Etiam vulputate odio et orci imperdiet eu sollicitudin neque sodales. Nunc quis quam tortor. Quisque viverra massa in tellus malesuada sed bibendum massa sollicitudin. Donec cursus purus aliquet nibh ultricies hendrerit. Suspendisse potenti. Vivamus egestas dictum arcu, vitae fringilla tortor egestas ac.</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 11:15:47', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(3, 0, 'profile_examples/a3.jpg', 1, '', '', 'Example number 3', '<p><strong>Phasellus feugiat euismod orci at adipiscing.</strong> Proin bibendum velit cursus mauris dapibus elementum. Mauris ultrices nisl felis. Sed lacinia tempor varius. Fusce venenatis rhoncus sem, et imperdiet lectus adipiscing sit amet. Pellentesque ut vulputate nisl. Sed ac mauris nunc, quis dignissim augue. Quisque et tincidunt augue. Vivamus in nisl id nulla pretium bibendum. Sed pharetra ullamcorper aliquam. Sed nec est diam, vel laoreet mauris.</p>', '', '', '2010-05-26 00:00:00', '2010-05-25 11:15:15', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(4, 1, '', 0, '', '', 'Mr. Natoque et Magnis', '<p><em>/'The service was brilliant! Ut luctus rhoncus mauris eu pharetra. Fusce dapibus aliquam nisl, non lacinia ligula pretium sit amet. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus./'</em></p>/r/n<p><strong>Mr. Natoque et Magnis</strong></p>', '', '', '2010-05-25 00:00:00', '2010-05-25 11:23:40', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(5, 1, '', 0, '', '', 'Mss. Nulla Amet', '<p><em>/'Good quality of the products. Quisque fringilla diam quis lacus venenatis varius. Fusce imperdiet fringilla justo eu malesuada. Sed id nisl vulputate risus scelerisque suscipit. Nulla sit amet lorem non felis interdum venenatis. Fusce sollicitudin lorem ac erat varius sed mollis magna scelerisque./'</em></p>/r/n<p><strong>Mss. Nulla Amet</strong></p>', '', '', '2010-05-25 00:00:00', '2010-05-25 11:23:56', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(6, 2, '', 0, '', 'profile_examples/press1.pdf', 'How can I capture credit card information without a payment gateway?', '<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>If you do not have a payment gateway, but still want to accept Credit Cards for processing offline you can capture the credit card information using the Saved Credit Card payment method.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>To set this up go to&nbsp;<strong>System</strong>&nbsp;-&gt;&nbsp;<strong>Configuration</strong>&nbsp;and select&nbsp;<strong>Payment Methods</strong>&nbsp;from the left navigation. Once there you will see Saved CC as one of the available methods.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'><img style=/'padding: 0px; margin: 0px; border: 0px initial initial;/' src=/'http://www.magentocommerce.com/images/uploads/admin_payment_savedcc.jpg/' alt=/'image/' /></p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>To enable this option you will want to set the Enabled dropdown to Yes.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>You can change the Title of the method to whatever you like in the Title field.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Below this you can set the preferences of this payment method just as you do with all other payment methods. This includes the status of new orders placed with this method, the sort order as it will appear in the front-end in relation to the other methods, whether your customers must enter a card verification number, and the country and order amount filters for your customer to be able to use this method.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>When you are finished, select the Save Config button and you will be able to accept credit cards without integrating with a payment gateway.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Orders placed using this method will appear in the admin with the card number, name on card and expiration date displayed to the store owner. You can then take this information and use it to charge your customers using your preferred method.&nbsp;</p>', '', '', '2010-02-09 00:00:00', '2010-05-25 11:36:50', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(7, 2, '', 0, '', 'profile_examples/press2.pdf', 'How Do I Accept Checks and Money Orders as Payment?', '<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>To accept checks and money orders as payment for orders go to&nbsp;<strong style=/'padding: 0px; margin: 0px;/'>System</strong>&nbsp;-&gt;&nbsp;<strong style=/'padding: 0px; margin: 0px;/'>Configuration</strong>. Select Payment Methods from the left navigation. The current release of Magento supports offline payment using checks and money orders. Future releases will support the acceptance of electronic checks on the site.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'><img style=/'padding: 0px; margin: 0px; border: 0px initial initial;/' src=/'http://www.magentocommerce.com/images/uploads/admin_payment_checks_thumb.jpg/' alt=/'image/' /></p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>To display this method to customers in the checkout process you must select Yes from the enabled dropdown.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>You are able to edit the title of the payment method by entering the text in the title field. The text entered here is what is displayed on the payment information page and on all order correspondence with the customer, including order confirmation emails, invoices, and the order history in the customer&rsquo;s account. If you only want to accept Money Orders and not Checks, for example, you can rename the method to Money Orders.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>You can then select the status you want orders placed using Checks and Money Orders. Any orders placed using the Checks / Money Orders payment method will be displayed in the admin panel with this status.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Enter the name and address of your company so that your customers know where the send the checks and to whom the checks will be payable. This information will appear in the checkout process for your customers to see.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>As with all payment methods, you can add country and order amount filters to determine which customers will be able to use this payment method. You will also be able to move the positioning of the Checks / Money Orders method around on the payment page by changing the sort order. The lowest number will be displayed in the highest position on the page.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Below this payment method is the Purchase Orders option. This is also an offline method, but it is different from Checks and Money Orders. This is intended to be used when you and the customer have established a credit system, where they are given a Purchase Order number to enter during the checkout process and you can cross-reference this number with a payment option that you have or will arrange with the customer.&nbsp;</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 11:33:08', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(8, 2, '', 0, '', 'profile_examples/press3.pdf', 'What are Tax Rules and How Do I Use Them?', '<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Tax Rules are defined as a combination of a Customer Tax Class and a Product Tax Class with a Tax Rate (see&nbsp;<a style=/'color: #0068b7; text-decoration: none; padding: 0px; margin: 0px;/' title=/'What are tax classes? (product and customer)/' href=/'http://www.magentocommerce.com/knowledge-base/entry/what-are-tax-classes-product-and-customer/'>What are tax classes? (product and customer)</a>). Each customer will be assigned a class and each product is assigned a tax class. Each region is assigned a set of up to five tax rates. Based on the class of the customer and the class of the products in the shopping cart, and the region (this can be the shipping address, billing address, or shipping origin) the system will calculate out the appropriate tax.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>To create a Tax Rule go to&nbsp;<strong>Sales</strong>&nbsp;-&gt;&nbsp;<strong>Tax</strong>&nbsp;-&gt;&nbsp;<strong>Manage Tax Rules</strong>. Once there you will see a grid list of the Tax Rules you have created. To create a Tax Rule you will also have to create Tax Rates, along with the Tax Classes. See&nbsp;<a style=/'color: #0068b7; text-decoration: none; padding: 0px; margin: 0px;/' title=/'How do I define tax rates?/' href=/'http://www.magentocommerce.com/knowledge-base/entry/how-do-i-define-tax-rates-per-product-tax-rules//'>How do I define tax rates?</a>&nbsp;for more on setting Tax Rates.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Once you have created your Tax Classes and Tax Rates you can create rules. In this case we are going to create four rules. We have two different customer types, Retail customers and Wholesale Customers, and two different types of products, taxable and downloadable.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>In this example we are a store in California and we have created a tax rate of 8.25%. (NOTE: This is for example purposes only. Consult your state laws for tax rates). We have also left a rate as being 0%.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>The first Tax Rule we create is for Retail Customers buying taxable goods.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'><img style=/'padding: 0px; margin: 0px; border: 0px initial initial;/' src=/'http://www.magentocommerce.com/images/uploads/admin_tax_rule1.jpg/' alt=/'image/' width=/'455/' height=/'210/' /></p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>We select the Customer and Product class from the dropdowns and then select the Rate we want to use for this combination. In this case we want to use the first rate, 8.25%.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Select Save Rule and Retail customers with a shipping address in California will be charged a rate of 8.25% on all items marked as being Taxable Goods. That is set, but let&rsquo;s say we have downloadable items we don&rsquo;t want charge tax on. We create a new rule with the combination of the Retail Customer Tax Class and the Downloadable Items Product Tax Class and select the rate we want to charge.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>In this case the rate is the second we created, 0.0%, so customers will not be charged tax on these items.</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>Now that we have our retail customers set up with tax rates we need to set up the two rules for Wholesale Customers. We select the Wholesale Customer from the tax class, select Taxable Items and Rate 2. Then we do the same for Downloadable Items and we have our four tax rates created:</p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'><img style=/'padding: 0px; margin: 0px; border: 0px initial initial;/' src=/'http://www.magentocommerce.com/images/uploads/admin_taxrule2.jpg/' alt=/'image/' width=/'598/' height=/'203/' /></p>/r/n<p style=/'margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;/'>If you need to charge tax on shipping, you can do so by creating a Tax Rule for shipping. This means that you should create a Product Tax Class that will be applied to shipping. Navigate to&nbsp;<strong>System -&gt; Configuration</strong>, and click the Sales tab. In the Tax Calculation section, you can select which product tax class will be applied to the shipping, if you choose to tax shipping. You can also determine whether tax will apply before or after discounts, and how the region of the Tax Rate will be determined (billing address, shipping destination, or shipping origin).</p>', '', '', '2010-03-17 00:00:00', '2010-05-25 11:37:07', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(9, 3, 'profile_examples/article1pic.jpg', 0, 'profile_examples/article1.jpg', '', 'cnet Wireless', '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 11:54:31', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(10, 3, 'profile_examples/article2pic.jpg', 0, 'profile_examples/article2.jpg', '', 'cnet Security', '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 12:12:54', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(11, 3, 'profile_examples/article3pic.jpg', 0, 'profile_examples/article3.jpg', '', 'cnet Webware', '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 12:13:33', 1);
INSERT INTO `{$this->getTable('profile/profile')}` VALUES(12, 3, 'profile_examples/article4pic.jpg', 1, 'profile_examples/article4.jpg', '', 'cnet Business', '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.</p>', '', '', '2010-05-25 00:00:00', '2010-05-25 12:14:21', 1);

INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(1, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(2, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(3, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(4, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(5, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(6, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(7, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(8, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(9, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(10, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(11, 0);
INSERT INTO `{$this->getTable('profile/profile_store')}` VALUES(12, 0);
");

$installer->endSetup();


复制进去即可

4
资源模型
Model/Profile.php
Model/Mysql4/Profile.php
Model/Mysql4/Profile/Collection.php
三个文件,默认是这个顺序,
其中
Model/Mysql4/Profile.php由配置文件决定路径
Model/Mysql4/Profile/Collection.php由继承的一个文件决定,详细参看上面的帖子。

4.1
Model/Profile.php

<?php
/**
* Mason Web Development
*
* @category RichardMason
* @package RichardMason_Profile
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class RichardMason_Profile_Model_Profile extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('profile/profile');
}
}

4.2
Model/Mysql4/Profile.php
<?php
/**
* Mason Web Development
*
* NOTICE OF LICENSE
* This source file is subject to the Open Software License (OSL 3.0)
* Part of the code of this file was obtained from:
* -category Mage
* -package Mage_Adminhtml
* -copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* -license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @category RichardMason
* @package RichardMason_Profile
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class RichardMason_Profile_Model_Mysql4_Profile extends Mage_Core_Model_Mysql4_Abstract
{

/**
* Store model
*
* @var null|Mage_Core_Model_Store
*/
protected $_store = null;
public function _construct()
{
// Note that the profiles_id refers to the key field in your database table.
$this->_init('profile/profile', 'profile_id');
}
}

4.3

Model/Mysql4/Profile/Collection.php

<?php
/**
* Mason Web Development
*
* NOTICE OF LICENSE
* This source file is subject to the Open Software License (OSL 3.0)
* Part of the code of this file was obtained from:
* -category Mage
* -package Mage_Adminhtml
* -copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* -license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @category RichardMason
* @package RichardMason_Profile
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class RichardMason_Profile_Model_Mysql4_Profile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
protected $_previewFlag;
public function _construct()
{
parent::_construct();
$this->_init('profile/profile');
$this->_map['fields']['profile_id'] = 'main_table.profile_id';
}
/**
* Add Filter by store
*
* @param int|Mage_Core_Model_Store $store
* @return Mage_Cms_Model_Mysql4_Page_Collection
*/
public function addStoreFilter($store, $withAdmin = true)
{
if (!$this->getFlag('store_filter_added')) {
if ($store instanceof Mage_Core_Model_Store) {
$store = array($store->getId());
}
$this->getSelect()->join(
array('store_table' => $this->getTable('profile/profile_store')),
'main_table.profile_id = store_table.profile_id',
array()
)
->where('store_table.store_id in (?)', ($withAdmin ? array(0, $store) : $store))
->group('main_table.profile_id');
$this->setFlag('store_filter_added', true);
}
return $this;
}

}



5
IndexController.php

<?php
/**
* Mason Web Development
*
* @category RichardMason
* @package RichardMason_Profile
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class RichardMason_Profile_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction(){
$profiles = Mage::getModel('profile/profile')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$profiles->addFieldToFilter('category_id', 3);
$profiles->setOrder("creation_time", "DESC");
//print_r($profiles);
// echo $profiles->getData("content");
foreach($profiles as $n){
echo $n->getData("content");
echo "<br>";

}

echo "<br><br><br><br><br>222";
$profiles1 = Mage::getModel('profile/profile')->load(2);
echo $profiles1->getData("content");
echo "<br><br><br><br><br>222";
}
}










6
访问这个路径。。


7会出现下面的结果:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut dolor sit amet nisl elementum rhoncus et at lorem. Pellentesque quis felis quis eros fermentum interdum. Curabitur nibh lacus, varius quis fermentum sit amet, pretium ut enim. Proin euismod enim a ligula tristique volutpat.

后续:

public function indexAction(){


$resource = Mage::getModel('profile/profile')->_getResource();
$select = $resource->_getReadAdapter()->select()
->from($resource->getTable('profile/profile'))
->where('profile_id = ?', 2);

$data = $resource->_getReadAdapter()->fetchAll($select);

foreach($data as $da){
var_dump($da);
}

将_getAdapter()函数改成public,可执行,

分享到:
评论

相关推荐

    重写session机制,将session写入数据库,建表和注释写的都很清晰,已测试

    重写session机制,默认session是以临时文件形式存储在服务器,将session写入数据库,建表和注释写的都很清晰,已测试

    c# 读取串口写入数据库

    同时,为了同步这两个线程,可以使用`Mutex`或`SemaphoreSlim`等同步机制,确保串口读取线程不会在数据库写入线程未完成时尝试写入新的数据,防止数据丢失或错误。 最后,确保在应用程序关闭时正确关闭串口和数据库...

    C#读取XML文件并写入数据库

    在IT行业中,XML(eXtensible Markup Language)是一种常用的数据交换格式,它结构清晰、易于解析,常用于存储和传输...以上就是关于“C#读取XML文件并写入数据库”的详细讲解,希望对您在进行相关开发工作时有所帮助。

    Spring Batch读取txt文件并写入数据库的方法教程

    在本教程中,我们将探讨如何使用 Spring Batch 读取文本(txt)文件,并将读取到的数据处理后写入数据库。 首先,我们需要创建一个 Maven 项目,并在 `pom.xml` 文件中添加必要的依赖。这些依赖包括 `spring-boot-...

    易语言连接mysql数据库来实现读取写入修改实例

    在本实例中,我们将探讨如何使用易语言连接MySQL数据库,进行数据的读取、写入和修改操作。 首先,连接MySQL数据库是所有操作的基础。易语言提供了“数据库”类库,其中包含了一系列与数据库交互的命令。我们需要...

    EasyExcel 并发读取文件字段并进行校验,数据写入到新文件,批量插入数据到数据库

    下面我们将详细探讨如何使用EasyExcel实现并发读取文件字段、进行数据校验、将数据写入新文件以及批量插入到数据库的操作。 1. **EasyExcel介绍** EasyExcel是一款轻量级的Java Excel处理框架,它基于NIO和内存...

    java中excel数据写入数据库

    在Java编程中,将Excel数据写入数据库是一项常见的任务,特别是在数据处理和导入导出场景。这个场景通常涉及使用特定库来解析Excel文件,并通过某种框架(如Struts)与数据库进行交互。以下是对这个过程的详细解释:...

    asp.net 读取XML文件中的数据和写入数据库实例

    在这个实例中,我们将探讨如何在ASP.NET环境中读取XML文件中的数据,并将其写入数据库,以及反过来,如何从数据库中检索数据并更新XML文件。XML(可扩展标记语言)是一种用于存储和传输数据的标准格式,它具有良好的...

    C#通过NPOI库操作Excel,并将Excel数据导入Mysql数据库(自动建表)

    内容概要:本资源介绍了如何从利用Npoi库操作Excel,如相关读取单元格、行,介绍了如何对单元格数据格式进行操作,并分享了如何将Datatable数据导入Mysql数据库,方便项目管理。 阅读建议:此资源以如何读取Excel...

    C#读取大文本文件(4G)并将其批量写入数据库(每次100万条).zip

    在IT行业中,处理大文件是一项常见的任务,尤其是在数据处理、日志分析或数据库导入导出等领域。本示例聚焦于使用C#语言读取大型文本文件(如4GB大小)并将其批量写入数据库(每次处理100万条记录)。这种操作在大...

    使用POI解析excel文件并写入数据库

    这个项目实现的功能是读取excel文件中的数据,解析并写入数据库。 读取的excel文件位于项目目录下的 excel\0805.xlsx 使用IntelliJ IDEA开发此项目 使用MYSQL查看数据库 在MYSQL中运行项目db目录下的sql文件,创建...

    数据库读取写入修改

    数据库是存储和管理数据的核心工具,它允许程序员和系统管理员高效地执行各种操作,包括读取、写入和修改数据。在本篇中,我们将深入探讨数据库的基本概念、操作方式以及如何通过DLL(动态链接库)类实现这些功能。 ...

    行业分类-设备装置-读取数据方法以及数据写入方法.zip

    在IT行业中,设备装置的数据读取与写入是至关重要的环节,它们构成了设备与系统间交互的基础。本压缩包“行业分类-设备装置-读取数据方法以及数据写入方法.zip”聚焦于这一主题,提供了关于如何高效、安全地进行数据...

    kafka读取写入数据

    本文将深入探讨“Kafka 读取写入数据”的核心知识点,包括 Kafka 的基本架构、数据模型、生产者与消费者原理以及最佳实践。 ### 1. Kafka 基本架构 Kafka 是一个高吞吐量、分布式的发布订阅消息系统。它由以下几个...

    java解析Excel文件并把数据存入数据库和导出数据为excel文件SpringBoot代码示例

    1、java解析读取excel文件中的数据,并写入数据库。 2、java读取数据库数据,并导出为excel文件。 3、README.md中有详细的操作步骤示例。 使用说明: 1. 先使用postman导入:other/excel相关.postman_collection....

    c#从数据库读取写入记事本

    【C#从数据库读取写入记事本】的知识点主要涵盖以下几个方面: 1. 数据库操作: - 使用`SqlConnection`类建立与SQL Server的连接。`SqlConnection`是.NET Framework中用于与SQL Server交互的基础类,需要提供正确...

    spring Batch实现数据库大数据量读写

    Spring Batch 是一个强大的、可扩展的Java框架,专门用于处理批量数据处理任务,包括大量数据库数据的读取、处理和写入。它被设计为在企业级应用中处理大规模、高吞吐量的工作负载。本篇文章将深入探讨如何利用...

    Storm综合案例二Storm集群向Kafka集群读取数据并写入MySQL远程模式

    今天接上文,来实现一个Storm数据流处理综合案例的第二部分,Storm集群向Kafka集群源源不断读取数据,通过MyBatis写入到MySQL数据库,并部署为远程模式 准备工作 参考上文准备工作 代码编写 思路:Storm集群从...

    Delphi 如何将二维数组数据 以Blob 存入数据库中 并读取 工程

    在本场景中,我们将探讨如何在 Delphi 中将二维数组数据转换为 Blob 数据,然后存入 MySQL 数据库,并从数据库中读取出来。 首先,我们需要了解 Delphi 中的二维数组和 Stream 对象的概念。二维数组是多个一维数组...

    基于LabVIEW的Excel数据读取和写入.zip

    下面将详细讲解如何在LabVIEW中进行Excel数据的读取和写入操作,以及这一过程中的关键知识点。 1. **LabVIEW简介**: LabVIEW(Laboratory Virtual Instrument Engineering Workbench)是由美国国家仪器公司(NI)...

Global site tag (gtag.js) - Google Analytics