1

Am trying to connect to Database table using Zend_Db_Table_Abstract. To do this am following these steps

Step1: Created a class which extends Zend_Db_Table_Abstract

<?php
class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract{

protected $_name = "zfalbums";

public function getAlbums($id){
    $where = "id = $id";
    $row = $this->fetchRow($where);
    $row->toArray();
    return $row;
}
}

Step2: Calling above class in controller, like this

<?php

class IndexController extends Zend_Controller_Action
{

public function init()
{
    /* Initialize action controller here */
}

public function indexAction()
{
    ;

    $albums = new Application_Model_DbTable_Albums();
    $result = $albums->fetchAll()->toArray();
    print_r($result);
}
}

Step3: Accessing index controller by using local host url

However when try to run this controller following error is thrown

Fatal error: Class 'Application_Model_DbTable_Albums' not found in

Here is the my project structure

enter image description here

1 Answer 1

4

Rename your file Application_Model_DbTable_Albums.php to Albums.php and make sure inside it you have something like this

    Class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract
{

}
Sign up to request clarification or add additional context in comments.

2 Comments

@flex coz thats how Zend Autoloader works and save you from doing requre_once yourself.
Now class not found error is gone!. Thanks, but no data is returned from db. Any idea

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.