Jump to content

Jak

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jak's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, Can someone help me out with this, I dont know why it's not working: RewriteRule ^admin(/|$) admin.php [QSA,S=1] RewriteRule ^.*$ index.php [QSA,L] /test should go to /index.php /admin should go to /admin.php /admin/test should go to /admin.php If I comment out the second rule the first rule is matching the second two examples correctly, but the request still ends up at index.php, basically the skip flag isn't working. Any ideas? Thanks, Jack
  2. Yeah, basically one and two are completely different things, so extending them wouldn’t work and doesn’t make sense. Basically the system I’m building is modular, and based on MVC. Quick explanation: [list] [*]There is a “request” class which, based on the URL, loads a module (for example I have a front end “site” module, and a back end “admin” module). [*]The “one” class in my example above is actually the module class, and it does things like create a variable with the path to the folder that module is in (for including related files later) and creating the database connection. [*]The module then initializes one of many controller classes (“two” above) which deals with processing the actual request (add a product, view a product etc.). [*]The controller needs to use things like the database connection that was created by the module class, and so that’s why I need to parse the module object, to the controller. [/list] I don’t know if this makes sense, but basically one and two are very different things, and so you wouldn’t use extends.
  3. No, sorry, I don’t mean one class extending another, here is some code: [code]<?php class one { function __construct() { $this->prefs = /*some array of things*/; $this->db = new databaseConnection(/*user, pass etc...*/); } function init() { $this->two = new two($this); } } class two { function __construct($one) { $this->one = $one; $this->db = $this->one->db; } function loadSomething() { echo 'My parent is '.get_class($this->one).' i need to use my parents database connection'; $this->db->query(/*SOME SQL*/); // etc.... } } $myOne = new one(); ?>[/code] So the one object has a variable called two, which points to a two object, which contains a variable called one, which points to its parent object.
  4. Hi, I'm currently building a simple framework to build my websites on, and there is one thing I am doing a lot that just feels like bad practice. I am basically creating a lot of parent-child links between my objects, so I create my parent object, and then that uses one of many classes to create a child object (assigned to $this->child), however, because the child object needs access to variables in the parent object, I have to pass the parent object ($this) to the child in the constructor method and then in the child constructor assign that to $this->parent. Is this bad? I’m doing it quite a lot, and in some cases it goes a couple of levels deep. I can’t think of any other way to do it, as the child objects really are unique to the parents, and they need to know what object they were created by. Any thoughts? Thanks in advance, Jack
  5. Hey, someone helped me figure it out, for anyone thats interested, its because the first instance of A dosent exist until the constructor has finished running, and because B is created within the constructor when B tries to call the instance of A it dosent exist yet, and so it goes round and round.
  6. Hmm, i dont really understand. I thought the whole point of the singleton pattern was that only one instance of the class should exist, so surley the "but once per every object" thing shouldnt matter, because there should only be one. Every example of a singleton in php ive seen has created it like this (or similar), yet it dosent seem to work. Im sure it has something to do with that fact that the class getting the instance a second time is being created by the instance the first time. If i do this: [code]<?php class A { public static function instance() { static $instance; if(!isset($instance)) $instance = new A(); return $instance; } public function __construct() { new B; } } class B { public function __construct() { //A::instance(); } } $c = A::instance(); $c->test = 1; $d = A::instance(); echo $d->test; ?>[/code] It returns 1, as expected, so the singleton is working, just not when it is a child of something else. Is there any way to fix it, or is it a bug in PHP?
  7. Hmm, i dont get that, i just get Internal Server Error. Anyway, line 5 is "static public function instance()" i dont see anything wrong with that, is there? Im pretty sure there's no syntax error, because if i remove the "A::instance();" line inside class B its all fine. Im on PHP 5.2 by the way.
  8. Hi, I have a class that I’m using as a singleton and for some reason its just not working at all. Basically my A class (the singleton) is created, and the constructor creates a new B object (from the B class). The B class needs to use variables from the A classes instance, so its constructor calls the instance of A, but then it all goes wrong. When the instance of A is called for the second time it still thinks it doesent exist (the if is true) and so creates another instance of A, therefore running the constructor again, which in turn creates B again and so on (it gets stuck in a loop). I have no idea why this is, has anyone got any ideas? Here is an example piece of code that demonstrates the problem (although here it actually returns an Internal Server Error rather than getting stuck in a loop): [code]<?php class A { static public function instance() { static $instance; if(!isset($instance)) $instance = new A(); return $instance; } public function __construct() { new B; } } class B { public function __construct() { A::instance(); } } A::instance(); ?>[/code] Thanks in advance, Jack
  9. Hey, Dont worry, ive fixed it, not that i have any idea how. I rewrote the session handling class to work in a different way and the problem seems to have resolved itself.
  10. Hi, I’m using a custom session handling class in my application, however I’m having trouble with the session write method. I’m using __destruct methods in a couple of classes to modify values in the SESSION variable, but some (not all) of the changes I make are not being saved. At first I thought it was because PHP was running the session handlers write function before the __destruct methods in my classes, however I have since discovered that its not running the write method at all (sometimes). I added a line into each of the relevant functions to log what was happening to a file, this is what I got: [code]** NEW REQUEST ** SESSION CONSTRUCTOR SESSION READ FORM DESTRUCTOR ** NEW REQUEST ** SESSION CONSTRUCTOR SESSION READ VALIDATION DESTRUCTOR SESSION WRITE ** NEW REQUEST ** SESSION CONSTRUCTOR SESSION READ FORM DESTRUCTOR[/code] So on the first request (the initial page load) the session is being created, a form is created on the page, and the forms destructor is run. The second request is the post to the server from the form. The session is fine, the validation classes destructor is run (which writes validation data to the session variable) and then the session write function is run, ALL GOOD. On this occasion the form failed validation so the third request is the redirect back to the original form. The session is fine, the form destructor is fine (which removes the validation data that the validation class added, as this has been used earlier in the form class) however for some reason the session write method has NOT been run. Does anyone have any idea why this would happen? I’m completely confused, I assumed the write function would run at the end of every request, and it certainly should if the session data has changed. Thanks in advance, Jack
  11. That was exactly it. Thanks! :)
  12. Hi, I’m trying to run php via the command line but for some reason I’m getting errors about extensions that it cant find. If I go to the command line and type: [code]php[/code] I get a windows style alert box with: [quote]This application has failed to start because php_mbstring.dll was not found. Re-installing the application may fix this problem.[/quote] And then in the command line window this error appears: [code]PHP Warning:  PHP Startup: Unable to load dynamic library 'c:\php\ext\php_exif.dll' - The specified module could not be found.[/code] That is the correct path to the extension and both extensions are there. The weirdest thing about all of this is that when I run a php script through apache there are no errors. And if I do phpinfo() both of those two extensions are in the list and working perfectly. Any ideas? Thanks, Jack
  13. Cheers thats really helpful, very much appreicated.
  14. Hmmm, thats kinda all a bit over my head, all i know is im running windows to test and linux on the production server. So would you reccomend me writing my own class, or are there good ones out there that take care of all the usuall requirements? Cheers, Jack P.S. Did you have any luck with that imap thing with the UIDLs?
  15. Hi, I was just wondering if there was a "best practice" when it comes to using ImageMagick through PHP. Ive been using MagickWand on my local server, but my hosts dont support it, so i was wondering what the best alternative is really. Is there a standard class that everyone uses, or does everyone just write their own class / functions that directly access exec()? Thanks, Jack
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.