0

I have a folder structure like this and I'm trying to load the News model inside my controller:

<?php
/**
 * Login
 */
class Admin_NewsController extends Zend_Controller_Action {

    public function preDispatch() {
        $layout = Zend_Layout::getMvcInstance();
        $layout->setLayout('admin');
    }
    public function init() {
        $this->db = new Application_Admin_Model_DbTable_News();
    }

    public function indexAction() {

    }

    public function addAction() {
        //$this->getHelper('viewRenderer')->setNoRender();
        // Calls the Request object
        $request = $this->getRequest();

        if ($request->isPost()) {
            // Retrieves form data
            $data = array(
                "new_title" => $request->getParam('txtTitle'),
                "new_text" => htmlentities($request->getParam('txtNews')),
                "new_image" => $request->getParam('upName'),
                "new_published" => 1
            );
            // Inserts in the database
            if ($this->db->addNews($data)) {
                $this->view->output = 1;
            } else {
                $this->view->output = 0;
            }
        } else {
            $this->view->output = 0;
        }

        $this->_helper->layout->disableLayout();
    }
}

And my model:

<?php

class Application_Admin_Model_DbTable_News extends Zend_Db_Table_Abstract
{
    protected $_name = 'news';

    public function addNews($data) {
        $this->insert($data);
    }
}

Althoug I'm getting this error: alt text

1 Answer 1

1

Since your News class belongs to the module, its name should be Admin_Model_DbTable_News, without Application_ prefix.

See more on autoloading within modules at http://framework.zend.com/manual/en/zend.loader.autoloader-resource.html#zend.loader.autoloader-resource.module

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

3 Comments

ok, but now it says Fatal error: Class 'Admin_Model_DbTable_News' not found
Do I have to use some autoloader?
The only thing you need to make sure is that your module bootstrap is extending Zend_Application_Module_Bootstrap as in: class News_Bootstrap extends Zend_Application_Module_Bootstrap

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.