2
votes

I'm trying to insert data in database, but have the problem with model . please help Fatal error: Class 'Model_DbTable_Vendor' not found in D:\wamp\www\mmz\application\controllers\VendorController.php on line 9

application/configs/application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0 

resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
[resources.frontController.baseUrl = "/mmz/public"]
resources.view[] = ""
resources.view.doctype = "html5"
resources.view.encoding = "utf-8"
resources.view.contentType = "text/html;charset=utf-8"
resources.modules[] = "admin"

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "catalog"
resources.db.isDefaultTableAdapter = true
resources.db.params.charsert = "utf8"

[staging : production] 
resources.view[] =
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Bootstrap.php

 <?php

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

        protected function _initViewHelpers() {
            $view = new Zend_View();
            $view->headTitle('Main Title')->setSeparator(' - ');
        }

    }

application/models/DBTable/Vendor.php

<?php

require_once("Zend/Db/Table/Abstract.php");

class Model_DbTable_Vendor extends Zend_Db_Table_Abstract {

    protected $_name = "vendor";

    public function init() {

        $this->getAdapter()->query("SET NAMES 'utf8'");
    }

    public function addVendor($vendor_name) {
        $this->insert($vendor_name);
    }
}

application/forms/Vendor.php

<?php
class Application_Form_Vendor extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');

        $this->addElement('text', 'vendor_name', array(
            'label'      => 'Vendor name:',
            'required'   => true,
            'filters'    => array('StringTrim')
           // 'validators' => array(
           //     'EmailAddress',
            //)
        ));

        $this->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'Add new',
        ));

        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));
    }
}

application/controllers/VendorController.php

<?php

class VendorController extends Zend_Controller_Action {

     protected $vendor;

    public function init() {
        /* Initialize action controller here */
         $this->vendor = new Model_DbTable_Vendor();
    }

    public function indexAction() {
        $request = $this->getRequest();
        $form = new Application_Form_Vendor();
        $this->view->form = $form;

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $vendor_name = $form->getValue('vendor_name');
                $this->vendor->addVendor($vendor_name);
            }
        }

    }

}

application/views/scripts/vendor/index.phtml

Vendor form
<?php
$this->form->setAction($this->url());
echo $this->form;
1
where is your autoloader setup / config? ZF won't know where to look for your Model class if you haven't registered a Model_ namespace with the autoloaderJamesHalsall
isn't Model_ the standard path? My guess is, that the autoloader trips over the path to the model class: try using a folder name that is in exact the same case as the model pseudo namespace: application/models/DbTable/Vendor.phpcypherabe
use Application prefix when calling the model from controller.Ronak K

1 Answers

2
votes

instead of ,

public function init() {
        /* Initialize action controller here */
         $this->vendor = new Model_DbTable_Vendor();
    }

use,

public function init() {
        /* Initialize action controller here */
         $this->vendor = new Application_Model_DbTable_Vendor();
    }

in .ini file

resources.frontController.params.displayExceptions = 1 // error reporting on