Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2007, 02:40 PM
Junior Member
 
Join Date: Nov 2007
Location: Sweden
Posts: 12
Question Script can't find file/class, (set_include_path problem)

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";
    }

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-29-2007, 07:55 PM
Junior Member
 
Join Date: Nov 2007
Location: Elmshorn, Germany
Posts: 14
Send a message via ICQ to t-mow
Default

you made a mistake in the set_include_path() function: you'll have to separate all directories which should be included by the php constant PATH_SEPARATOR, not just by a dot, which connects all paths to one single path at the moment
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-30-2007, 06:15 PM
Junior Member
 
Join Date: Nov 2007
Location: Sweden
Posts: 12
Default

Quote:
Originally Posted by t-mow View Post
you made a mistake in the set_include_path() function: you'll have to separate all directories which should be included by the php constant PATH_SEPARATOR, not just by a dot, which connects all paths to one single path at the moment
Right, did think of that but when trying with PATH_SEPERATOR it didn't solve my problem so I decided to print it and it isn't set on my machine. Where is that constant supposed to be set?

I'm running Windows XP with WAMP5.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-30-2008, 07:05 PM
Junior Member
 
Join Date: Dec 2007
Posts: 8
Default

$include_paths = array(
//your paths separated by a comma (,)
//i would leave get_include_path() out,
//as you have already included your library,
//and apparently aren't planning on using PEAR
);
set_include_path(implode(PATH_SEPARATOR, $include_paths));
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:38 PM.