阅读本教程http://alanstorm.com/magento_models_orm 在过去3天工作,请帮助,如果你可以
但是我收到了这个错误: -
加载ID为1的博客帖子 致命错误:在第225行的/var/www/html/magento/app/code/core/Mage/Core/Model/Abstract.php中调用boolean上的成员函数load()
/var/www/html/magento/app/code/local/Alanstormdotcom/Weblog/etc/config.xml
<config>
<modules>
<Alanstormdotcom_Weblog>
<version>0.1.0</version>
</Alanstormdotcom_Weblog>
</modules>
<frontend>
<routers>
<weblog>
<use>standard</use>
<args>
<module>Alanstormdotcom_Weblog</module>
<frontName>weblog</frontName>
</args>
</weblog>
</routers>
</frontend>
<global>
<models>
<weblog>
<class>
Alanstormdotcom_Weblog_Model
</class>
<resourceModel>
weblog_mysql4
</resourceModel>
</weblog>
<weblog_mysql4>
<class>Alanstormdotcom_Weblog_Model_Mysql4</class>
<entities>
<blogpost>
<table>blog_posts</table>
</blogpost>
</entities>
</weblog_mysql4>
</models>
<resources>
<weblog_write>
<connection>
<use>core_write</use>
</connection>
</weblog_write>
<weblog_read>
<connection>
<use>core_read</use>
</connection>
</weblog_read>
</resources>
</global>
/var/www/html/magento/app/code/local/Alanstormdotcom/Weblog/controllers/IndexController.php
<?php class Alanstormdotcom_Weblog_IndexController extends Mage_Core_Controller_Front_Action {
public function testModelAction() {
$params=$this->getRequest()->getParams();
$blogpost=Mage::getModel('weblog/blogpost');
echo("Loading the blogpost with an ID of ".$params['id']);
$blogpost->load($params['id']);
$data=$blogpost->getData();
var_dump($data);
} } ?>
/var/www/html/magento/app/code/local/Alanstormdotcom/Weblog/Model/Mysql4/Blogpost.php
<?php
class Alanstormdotcom_Weblog_Model_Mysql4_Blogpost extends Mage_Core_Model_Mysql4_Abstract {
protected function _construct()
{
$this->_init('weblog/blogpost', 'blogpost_id');
} } ?>
/var/www/html/magento/app/code/local/Alanstormdotcom/Weblog/Model/Blogpost.php
<?php
class Alanstormdotcom_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract{
protected function _construct(){
$this->_init('weblog/blogpost');
} } ?>
答案 0 :(得分:1)
试试这个
<config>
<modules>
<Alanstormdotcom_Weblog>
<version>0.1.0</version>
</Alanstormdotcom_Weblog>
</modules>
<frontend>
<routers>
<weblog>
<use>standard</use>
<args>
<module>Alanstormdotcom_Weblog</module>
<frontName>weblog</frontName>
</args>
</weblog>
</routers>
</frontend>
<global>
<models>
<weblog>
<class>Alanstormdotcom_Weblog_Model</class>
<resourceModel>weblog_mysql4</resourceModel>
</weblog>
<weblog_mysql4>
<class>Alanstormdotcom_Weblog_Model_Mysql4</class>
<entities>
<blogpost>
<table>blog_posts</table>
</blogpost>
</entities>
</weblog_mysql4>
</models>
<resources>
<weblog_write>
<connection>
<use>core_write</use>
</connection>
</weblog_write>
<weblog_read>
<connection>
<use>core_read</use>
</connection>
</weblog_read>
</resources>
</global>
模型和资源模型应该在同一行