Results 1 to 3 of 3

Thread: Can you use a class method to include files?

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Can you use a class method to include files?

    Hi all,

    I want to be able to include files through a class. Here's a stripped down version of the class I've got going to give you an idea of what I'm trying to achieve:

    Code:
    class mm3 {
    	
    	// getCSS() - Returns standard CSS files depending on page/version.
    	public function getCSS($page, $version){
    		switch($page){
    			case "inventory":
    				include mmPHPPath.'includes/css-inventory.php';
    			default:
    				return false;
    		}
    	}
    	
    }
    But this isn't working. Nothing happens.

    mmPHPPath is a constant. If I changed "include" to "echo", the correct PHP path to the file is shown. If I change mmPHPPath to mmInvURL (another constant), then I get a path that if pasted into the browser also brings up the correct file. So I know it's pointing to the right place, but I'm not getting a result.

    If I use "require" the script halts, but if I use "include" with a try...catch block the catch statements don't execute.

    Blarg! Thanks for any help.
    My site: FreshCut :)

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try using:

    Code:
    include(mmPHPPath.'includes/css-inventory.php');
    instead.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Still nothing.

    This also results in nothing:

    Code:
    				try{
    					include(mmPHPPath.'includes/css-inventory.php');
    				} catch(Exception $e){
    					echo 'Message: ' .$e->getMessage();
    				}
    Edit: RATS! It turned out to be a stupid typo in my constants. But shouldn't include() throw an exception if it doesn't find the file? How are you supposed to debug include()?

    Thanks!
    Last edited by jlizarraga; 06-26-2009 at 08:05 PM.
    My site: FreshCut :)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •