Old 23-05-2008, 18:14   #1 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
PHP Help...

I know there are some neat PHP programmers on here, so I bring you a problem.

index.php
PHP Code:
<?php

// Define the base path
$folder_level "";
while (!
file_exists($folder_level."_core/settings/config.php")) 
    {
    
$folder_level .= "../"
    }
define("BASEDIR"$folder_level);

// Sanitise $_SERVER globals
$PHP_SELF ltrim($_SERVER['PHP_SELF']);
// Path definitions
define("CORE"BASEDIR."_core/"); // Path to where the class files are located
define("CLASSES"BASEDIR."_core/classes/"); // Path to where the class files are located
define("FUNCTIONS"BASEDIR."_core/functions/"); // Path to where the function files are located
define("SETTINGS"BASEDIR."_core/settings/"); // Path to where the settings files are located
define("VIEW"BASEDIR."_core/views/"); // Path to where the view files are located
define("CONTROLLERS"BASEDIR."_core/controllers/"); // Path to where the controller files are located
define("IMAGES"BASEDIR."_img/"); // Path to where the class files are located

include("".CORE."uri.php");

$load->view("header");
$load->view("footer");

?>

load.php
PHP Code:
<?php

// This file produces all the loading functionality of the framework.

class load
{
    function 
view($view)
    {
        include(
"".VIEW."".$view.".php");
        return 
$this;
    }
    
    function 
controller($controller)
    {
        include(
"".CONTROLLERS."".$controller.".php");
        return 
$this;
    }
}

$load = new load;
?>

uri.php
PHP Code:
<?php

// This file manipulates the URI's
include("".CORE.""."load.php"); //  Include the load class



$uri $_SERVER['REQUEST_URI'];

$uri2 explode("/index.php/"$uri);

global 
$controller;
$controller $uri2['1'];

$load->controller($controller);

?>

Ok so what I'm trying t achieve is that when the user goes to index.php/helloworld, the helloworld controller will display. Thats exactly what the uri.php file does. I've checked that I am stripping the right bit down and I am passing it into the function...but the function won't handle it.

The simple question is how can I pass a variable to a function and make it work?

The longer question is, should I be coding PHP after 3 hours mountain biking?! lol.

Any help appreciated
__________________
If it works, it's valid.
  Reply With Quote
Old 24-05-2008, 06:34   #2 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
Anybody have an ideas as how to fix this? Or see where I've gone wrong?

I know it's a saturday but I've seen some people lurking around other threads
__________________
If it works, it's valid.
  Reply With Quote
Old 24-05-2008, 07:02   #3 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,152
I'm not sure, but I think this:
PHP Code:
$controller $uri2['1']; 

Should be this?
PHP Code:
$controller $uri2[1]; 

Sorry i'm a newbie with the OOP stuff in PHP.

Anyway, when bug fixing try echoing variables so you know you are doing it right. What error messages are you getting?
  Reply With Quote
Old 24-05-2008, 07:24   #4 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
I did do that with the uri.php file. I echoed the $_SERVER['REQUEST_URI']; to see what it was getitng, and then I echoed the $uri['0'] and ['1'] and ['2'] to see what it echoed. I'll try taking the quotes out to see if it makes any difference.
__________________
If it works, it's valid.
  Reply With Quote
Old 24-05-2008, 07:40   #5 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
OK guys. I've got it working. :P

View it working!!

It's not much visually at the moment :P But it works :P

Now I have to build a class to use in the controller so I can load the view files. xD

Thanks!
__________________
If it works, it's valid.
  Reply With Quote
Old 24-05-2008, 11:13   #6 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 815
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Is this a home made MVC system ?

Surely it would be easier just to install CI ?!
__________________
  Reply With Quote
Old 24-05-2008, 12:11   #7 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
Yea it's my own made MVC system :p

It would be easier to install CI, which is what I did initially. But then there were some drawbacks I had like when I used a .htaccess file to get rid of the index.php part, I couldn't show any images...but with this system I can. Plus I know how it all works and where''s the fun in downloading CI and installing it?!
__________________
If it works, it's valid.
  Reply With Quote
Old 25-05-2008, 05:38   #8 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,152
What did you do to the code to get it working then? Also what was the problem with images when using .htaccess?
  Reply With Quote
Old 25-05-2008, 06:00   #9 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,733
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
The problem was in my controller. I hadn't put it into a class so I couldn't use the $load-> function. But then I needed to decalre $load again.

The problem with the .htaccess file was that when I tried to include Index of /_img for example, it thought I was calling upon CI, and couldn't process it because _img isn't a controller. The same happened with the .css

I guess the main reason behind doing this for myself rather than installing CI was that I really hadn't got a clue how CI worked. So I set out to make this framework to see how it's done. Now I have done it and have the basics working, I'm going to make it look better, and now have a function fail_gracefully() so that the application doesn't spit out dreaded PHP errors, but nice looking errors that report into an error log, so I can debug it later on. Obviously I won't turn off any PHP errors until I know it's all working and I change everything to use the fail_gracefully function.

Plus my best mate has his portflio up and running, and he has a few PHP scripts, an upload script for one, and a blog script. But now I can put in my portfolio "PHP Framework" :P
__________________
If it works, it's valid.
  Reply With Quote
Old 27-05-2008, 04:54   #10 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 815
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Hmmm, can't say that I've experienced the same problem as you with the images or CSS files not working and I use .htaccess too...

Good for you though on wanting to discover the ins and outs of an MVC system, it will definitely help in the future to understand what goes on.
__________________
  Reply With Quote
Old 27-05-2008, 05:08   #11 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,152
I've had the .htaccess problem you describe before, you need to ensure you are not rewriting urls for files that actually exist. This block of code should do it.

Code:
RewriteEngine On # Prevent links to real files from being rewritten RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*/ - [L] # SEO Friendly Links RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?controller=$1 [L]
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8