Jump to content
Stef's Coding Community


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About 9three

  • Rank
    New member
  1. Hey, Now that I'm implementing namespaces, PDO is no longer being found. I'm doing: $this->db = new PDO('mysql:dbname=db;host=localhost', 'root', ''); It's trying to find application\path\PDO.php which is not the case. I tried doing: $this->db = new \PDO('mysql:dbname=db;host=localhost', 'root', ''); but that didn't work. The current namespace I'm using is: use \application\database as Mapper; Then I did: $this->db = new Mapper\PDO('mysql:dbname=db;host=localhost', 'root', ''); But that was no good either. It keeps looking for a physical file PDO.php. Not sure where I'm going wrong?
  2. Hey, Instead of using a switch statement like on the Advanced PHP video, I'm doing this: public function route() { $controllerClass = 'application/controllers/' .$this->getController(). 'Controller.php'; $className = $this->getController().'Controller'; if (file_exists($controllerClass)) return new $className($this->getController(), $this->getAction()); else return new errorController($this->getController(), $this->getAction()); } As you can see, the $className stores the actual class name. The problem is that I can't use namespaces when I do this. Controller\$className(); -- returns a syntax error. Not sure if this is something that still needs to get fixed as I know namespaces are still new to PHP. Or does someone know a workaround?
  3. Yep, seems pretty clear to me this is the route I need to take. Thanks.
  4. Hm, seems that works out ok for every other page that is not the index. For example, If the URI is www.domain.com/ The code knows that the user is on the main page, so it will output the index.php page for them. But what if I wanted to add a link AND keep them on the main page without having to do a www.domain.com/index/?ref=variable ? I wouldn't be able to do www.domain.com/?ref=variable because it would take it in as a whole string. I would need to do www.domain.com/index/?ref=variable in order for it to work correctly. But now that I think about it, I may have to do a work around, if I want to implement this. Maybe doing something like: if "?" was found use parse_str and use the index controller else explode the URI and continue as normal What do you think?
  5. I can't do that because it will take the whole thing as a string. IE. domain.com/home?ref=variable The whole string would be "home?ref=variable" and it will return a 404 (In my case, I created a check, if a file is not found it throws a 404 error). Basically what I'm looking for is still the same functionality that GET globals bring.
  6. Hello, Now that I'm using htaccess to access my pages and using $_SERVER['REQUEST_URI'] to strip the URI and grab the pages it's requesting, I am no longer able to use $_GET variables. I used to use GET variables as a way to show dynamic information. Example: $ref = $_GET['ref']; if ($ref == 'home') //Show Home information Now because I'm using the entire URI when I do something like domain.com/?ref=home, "?ref=home" is treated as a string. Which is expected because I'm exploding everything within each forward slash. My question is, how can I continue to use $_GET variables or something close to what I used before? I've noticed some sites, such as, last.fm which have in their url last.fm/?artist=some_variable_here That's the same effect I'm trying to accomplish. thanks
  7. argh, I was afraid of this answer. I was hoping that people could not know my structure. Although they can't access it because of the rewrites, but still
  8. I'm also having this issue and it isn't a href thing. I'm loading css, and js files externally and they are not referencing correctly. Usually by adding a "/" it fixes the problem, but it didn't. I also tried href="../../path/to/css.css" and href="../path/to/css.css", but it never finds the correct path. The only way I got it to work was by actually doing: http://localhost/application/views/css/global.css Now obviously I don't want to have to keep referencing files like that. Do you know how to fix this problem? My structure is as follow: index.php .htaccess --------------------application ----------------------------------------models ----------------------------------------controllers ----------------------------------------views ------------------------------------------------------------css ------------------------------------------------------------js ------------------------------------------------------------header.php ------------------------------------------------------------footer.php ------------------------------------------------------------(directories for each page like home/about/... etc etc..) In my root index.php file, I have a front controller that initiates a new object for me from my abstract controller. Which then calls a method called render(). Render has the following: public function render() { $directory = $this->getController(); $file = !empty($directory) ? $directory : 'index.php'; require_once $_SERVER['DOCUMENT_ROOT'].'application/views/header.php'; //require_once $_SERVER['DOCUMENT_ROOT'].'/'.$file; //require_once $_SERVER['DOCUMENT_ROOT'].'/application/views/footer.php'; } Hope someone can see the problem. thanks.
  • Create New...