0

I realize there are tons of tutorials online, I've looked at them, followed them and they work but now I'm trying to create my own model and I seem to be missing something. My problem: When I try to run my indexAction it just displays NULL, I have put data into my table and yes my table does exist. The table name is fit with fit_id being the primary key

Here is my config file

<models>
        <krauskopf_ymm>
            <class>Krauskopf_Ymm_Model</class>
            <resourceModel>ymm_resource</resourceModel>
        </krauskopf_ymm>

        <ymm_resource>
            <class>Krauskopf_Ymm_Model_Resource</class>
            <entities>
                <krauskopf_ymm>
                    <table>fit</table>
                </krauskopf_ymm>
        </entities>
        </ymm_resource>

</models>

Here is my Model, Krauskopf/Ymm/Model/Ymm.php

<?php
class Krauskopf_Ymm_Model_Ymm extends Mage_Core_Model_Abstract{

  public function _construct(){

    $this->_init('krauskopf_ymm/ymm');
  }

 }

Here is my Resource Krauskopf/Ymm/Model/Resource/Ymm.php

<?php
class Krauskopf_Ymm_Model_Resource_Ymm extends Mage_Core_Model_Resource_Db_Abstract{

 protected function _construct(){

    $this->_init('krauskopf_ymm/ymm', 'fit_id');
 }

}

Here is my collection Krauskopf/Ymm/Model/Resource/Ymm/Collection.php

<?php
class Krauskopf_Ymm_Model_Resource_Ymm_Collection extends     Mage_Core_Model_Resource_Db_Collection_Abstract{

  protected function _construct(){
    $this->_init('krauskopf_ymm/ymm');
  }

}

When I try to run my indexAction it just displays NULL, I have put data into my table and yes my table does exist. The table name is fit with fit_id being the primary key

IndexController.php

    public function indexAction(){
    $model = Mage::getModel('krauskopf_ymm/ymm');
    $data = $model->getData(1);
    var_dump($data);

}
1
  • I had to change the file structure to put my "resource" into Model/Mysql4 and extend my Ymm.php from Mysql4_Abstract. Then I had to move my Ymm/Collection.php file into Model/Mysql4/Ymm/Collection
    – codkra
    Commented Jul 24, 2015 at 15:12

1 Answer 1

1

Replace $data = $model->getData(1); with

$model->load(1);
$data = $model->getData()
1
  • I now get this error from my error log. codkra-osx:~ codkra$ /Users/codkra/Documents/Magento/var/report/1114252767197 ; exit; /Users/codkra/Documents/Magento/var/report/1114252767197: line 14: syntax error near unexpected token }' /Users/codkra/Documents/Magento/var/report/1114252767197: line 14: #13 {main}";s:3:"url";s:14:"/Krauskopf_Ymm";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}'
    – codkra
    Commented Jul 24, 2015 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.