Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

A database insert question , help
 
Jason Zhang
Jr. Member
 
Total Posts:  11
Joined:  2009-05-17
 

Hi all,
My main PHP codes:
Cartz/Hotel/controllers/MyController.php:
<?php
class Cartz_Hotel_MyController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$room = Mage::getModel('hotel/room');
}

public function roomAction()
{
$this -> loadLayout();
$this -> renderLayout();
}

public function sqlAction()
{
$room = Mage::getModel('hotel/room');
$room->insert();
}
}

Cartz/Hotel/Model/Room.php
<?php
class Cartz_Hotel_Model_Room extends Mage_Core_Model_Abstract
{
public function __construct()
{
$this -> _init('hotel/room');
}

public function insert()
{
$this -> setName('test');
$this -> save();
}
}

Cartz/Hotel/Model/Mysql4/Room.php
<?php
class Cartz_Hotel_Model_Mysql4_Room extends Mage_Core_Model_Mysql4_Abstract
{
public function __construct()
{
$this -> _init('hotel/room', 'id');
}
}
-----------------------------------------------------
Cartz/Hotel/etc/config.php
<?xml version="1.0"?>
<config>
<modules>
<Cartz_Hotel>
<version>0.1.0</version>
</Cartz_Hotel>
</modules>
<frontend>
<routers>
<hotel>
<use>standard</use>
<args>
<module>Cartz_Hotel</module>
<frontName>hotel</frontName>
</args>
</hotel>
</routers>
<layout>
<updates>
<hotel>
<file>hotel.xml</file>
</hotel>
</updates>
</layout>
</frontend>
<global>
<blocks>
<hotel><class>Cartz_Hotel_Block</class></hotel>
</blocks>
<models>
<hotel>
<class>Cartz_Hotel_Model</class>
<resourceModel>hotel_mysql4</resourceModel>
</hotel>
<hotel_mysql4>
<class>Cartz_Hotel_Model_Mysql4</class>
<entities>
<room>
<table>rooms</table>
</room>
</entities>
</hotel_mysql4>
</models>
<resources>
<hotel_setup>
<setup>
<module>Cartz_Hotel</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</hotel_setup>
<hotel_write>
<connection>
<use>core_write</use>
</connection>
</hotel_write>
<hotel_read>
<connection>
<use>core_read</use>
</connection>
</hotel_read>
</resources>
</global>
</config>

if I execute the sql action, then display below:
Fatal error: Class Cartz_Hotel_Model_Mysql4_Room contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Mage_Core_Model_Resource_Abstract::_construct) in D:\xampp\htdocs\magento\app\code\local\Cartz\Hotel\Model\Mysql4\Room.php on line 8

but if I change the __construct to protected, it will display:
Fatal error: Access level to Cartz_Hotel_Model_Mysql4_Room::__construct() must be public (as in class Mage_Core_Model_Resource_Abstract) in

What is the matter? thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
saurabhperiwal
Member
 
Total Posts:  35
Joined:  2010-05-05
 

I am facing same problem, let me know if you resolved it

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top