Everything is working fine until I try to use files from the /models directory. I believe there is a problem with my set_include_path in index.php but can't find the problem with that line.
Error message
Code:
exception 'Zend_Exception' with message 'File "Transactions.php" was not found' in C:\Program\wamp\ZendFramework-1.0.2\library\Zend\Loader.php:159 Stack trace:
#0 C:\Program\wamp\ZendFramework-1.0.2\library\Zend\Loader.php(91): Zend_Loader::loadFile('Transactions.ph...', Array, true)
#1 C:\Program\wamp\www\ekonomi\application\controllers\IndexController.php(11): Zend_Loader::loadClass('Transactions')
#2 C:\Program\wamp\ZendFramework-1.0.2\library\Zend\Controller\Action.php(129): IndexController->init()
#3 C:\Program\wamp\ZendFramework-1.0.2\library\Zend\Controller\Dispatcher\Standard.php(214): Zend_Controller_Action->__construct(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http), Array)
#4 C:\Program\wamp\ZendFramework-1.0.2\library\Zend\Controller\Front.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 C:\Program\wamp\www\ekonomi\index.php(33): Zend_Controller_Front->dispatch()
#6 {main}
Fatal error: Class 'Transactions' not found in C:\Program\wamp\www\ekonomi\application\controllers\IndexController.php on line 24
File structure, running on my Windows XP machine.
Code:
/www
/ekonomi
/application
/controllers
IndexController.php
/models
Transactions.php
/views
/filters
/helpers
/scripts
/index
add.phtml
delete.phtml
edit.phtml
index.phtml
/styles
/bluesky
bluesky.css
footer.phtml
header.phtml
config.ini
index.php
.htaccess
index.php
PHP Code:
<?php
date_default_timezone_set('Europe/Stockholm');
set_include_path('.' .
'../../ZendFramework-1.0.2/library' .
'./application/models' .
get_include_path());
include "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
// Load Configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// Setup Database
$db = Zend_Db::factory($config->db->adapter,
$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
// Setup Controller
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->setControllerDirectory('./application/controllers');
// run!
$front->dispatch();
IndexController.php, it's here the loadclass method is used.
PHP Code:
<?php
/** Zend_Controller_Action */
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
// Trying to load the Transactions class with a catch to write the error message a little more easy to read, if there is an error.
try {
Zend_Loader::loadclass('Transactions');
} catch (Exception $e) {
$temp = explode("#", $e);
foreach($temp as $key => $value) {
if ($key > 0) {
echo "#".$value . "<br />";
} else {
echo $value . "<br />";
}
}
}
}
public function indexAction()
{
$this->view->title = "Ekonomisk Översikt";
$transactions = new Transactions();
$this->view->transactions = $transactions->fetchAll();
}
public function addAction()
{
$this->view->title = "Lägg till transaktioner";
}
public function editAction()
{
$this->view->title = "Modifiera transaktioner";
}
public function deleteAction()
{
$this->view->title = "Ta bort transaktioner";
}
}