Jump to content


  • Content count

  • Joined

  • Last visited

Everything posted by MrAdam

  1. Hi,I was wondering if anybody knew of any PHP frameworks, specially suited for re-distributable applications? Modern frameworks are very good for splitting the different layers of an application, but they don't strike me as very distributable. I want a good structure and feel to the framework, without quite so much of the bloat and no special requirements to get it running. My application isn't huge, so doesn't need complex routing or multi-application capabilities, etc. Anybody have any to recommend?ThanksAdam
  2. Factory class structure

    Hey up everyone,I'm designing my own MVC-based framework. I'm not trying to re-invent the wheel or anything, I just want a simple, custom platform I can build my projects on. I'm implementing some objects (for example User) and creating a factory class (for example UserFactory) that handles constructing the object in various ways. There's an abstract base Factory class that each factory would extend to provide some generic functionality.I'm a little unsure how to structure the factory classes though. Would you say that it's acceptable to have both the User class and UserFactory class within the same file? That way I only need to include User and have UserFactory available. Or do you think it's more appropriate to have them in individual files, and have UserFactory include User?ThanksAdam
  3. Factory class structure

    No problem, thanks anyway. I've looked at several different frameworks and they all have their own approach to models, but none seem to be what I'm after. I'll keep digging!
  4. Factory class structure

    That makes sense, thanks.One other question.. Where would you think is the right place in a typical MVC-based framework to store such objects? For example the project I have in mind at the moment, certain parts of it (employees, clients, etc.) I want to create an Employee, or Client, etc. object to represent them. Obviously straight-forward OO, but where would that make sense in an MVC-based framework?Thanks for your help.Adam
  5. Factory class structure

    Thanks for your reply.I did think of autoloading the class, but due to the structure of the files I can't see any easy way to do that other than to have it check two directories. Would you say that's acceptable for autoloading? I want it to be as quick and snappy as possible, while keeping a very organised structure. I have the traditional "controller/", "model/" and "view/" directories. Only the "model/" is necessary for autoloading, as the controllers and views are resolved in a different manor.The second directory mentioned is a library of classes that contains the core components of the framework; the DB classes, the base Model, Controller & View, etc. That's already autoloaded in a Zend-like way. Would it be fine performance-wise to include the "model/" directory? Or if not, does another suggestion come to mind?Thanks again for your help..Adam
  6. Stuck with XSLT schema validation

    Hi guys,Managed to get some-what comfortable with XSLT now, but looking to validate my XML against my schema. I'm working with the following, pretty-simple XML: <products> <product id="1"> <title>Product A</title> <stock> <available>123</available> <ordered>123</ordered> <delivery>01/01/1970</delivery> </stock> <stats> <total_sold>123</total_sold> <per_order_average>123.45</per_order_average> <all_order_average>123.45</all_order_average> </stats> </product></products> My schema is: <?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="products"> <xs:complexType> <xs:element name="product"> <xs:attribute name="id" type="xs:integer" /> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="stock" /> <xs:complexType> <xs:sequence> <xs:element name="available" type="xs:integer" /> <xs:element name="ordered" type="xs:integer" /> <xs:element name="delivery" type="xs:date" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="stats" /> <xs:complexType> <xs:sequence> <xs:element name="total_sold" type="xs:integer" /> <xs:element name="per_order_average" type="xs:decimal" /> <xs:element name="all_order_average" type="xs:decimal" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:complexType></xs:element> I'm getting a lot of errors though. Am I on the right track? One area I can't seem to find a clear explanation of is attributes, with a complex type within them.In my XML above I have: <product id="1"> [...]</product> Which I'm using the following schema to validate: <xs:element name="product"> <xs:attribute name="id" type="xs:integer" /> <xs:complexType> [...] </xs:complexType> </xs:element> But I don't think that's correct. Any pointers or advise would be greatly appreciated!ThanksAdam
  7. Stuck with XSLT schema validation

    Realised a few obvious flaws with the previous XSD. Changed it to: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="products"> <xs:sequence> <xs:element name="product"> <xs:sequence> <xs:complexType> <xs:element name="title" type="xs:string" /> </xs:complexType> </xs:sequence> </xs:element> </xs:sequence> </xs:element></xs:schema> But get the error:
  8. Stuck with XSLT schema validation

    I decided to take things back to basics.With this XML: <?xml version="1.0"?><products> <product> <title>Product A</title> </product></products> And this XSD: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="products"> <xs:complexType> <xs:element name="title" type="xs:string" /> </xs:complexType> </xs:element></xs:schema> I receive the following error: Referring to this line: <xs:element name="title" type="xs:string" /> I feel like I'm missing something fundamental out? :sThanks
  9. Stuck with XSLT schema validation

    Sorry I posted a little prematurely there. I have managed to fix some of the issues, but I still get one: lement '{http://www.w3.org/2001/XMLSchema}complexType': The content is not valid. Expected is (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))) That's using PHP's DOM schema validator. I used an on-line validator and the error is: 4s-elt-invalid-content.1: The content of '#AnonType_products' is invalid. Element 'element' is invalid, misplaced, or occurs too often. Which refers to the line: <xs:element name="product" minOccurs="0" maxOccurs="unbounded"> The XSD in-full is now: <?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="products"> <xs:complexType> <xs:element name="product" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="id" type="xs:integer" /> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="stock"> <xs:complexType> <xs:sequence> <xs:element name="available" type="xs:integer" /> <xs:element name="ordered" type="xs:integer" /> <xs:element name="delivery" type="xs:date" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="stats"> <xs:complexType> <xs:sequence> <xs:element name="total_sold" type="xs:integer" /> <xs:element name="per_order_average" type="xs:decimal" minOccurs="0" /> <xs:element name="all_order_average" type="xs:decimal" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:complexType> </xs:element></xs:schema> Again.. very grateful for any help. Just need a push in the right direction..Thanks
  10. Hey up again,Quite comfortable with XSLT now, but have a puzzling problem. In my <xsl:output ... /> tag, I'm specifying the 'doctype-public' and 'doctype-system' attributes as the correct values for XHTML Strict 1.0: <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" /> However when I view the source code of the web page, the mark-up is HTML with an XHTML DOCTYPE? Also nothing is indented, like I'd expect to see with indent="yes"?Any help or advise would be greatly appreciated!Thanks
  11. Getting HTML back, instead of XHTML

    Thanks for your response. I'm using PHP's XSLTProcessor class. I solved the issue by using the unicode " " white-space character.Thanks again for your help.
  12. Getting HTML back, instead of XHTML

    Sorted, cheers. I switched it to "xml" and omitted the opening XML tag. I just have one more question though...I have some XHTML like: <h3><span>#1</span> Product Title</h3> Where "1" and "Product Title" are replaced by the XML value. That's all fine, but when it's processed the space between the closing span tag and the start of the title text is stripped out. So the result looks like: I came across the "xml:space" attribute:<h3 xml:space="preserve"> This works works visually, but oddly it's still shown within the source afterwards..?Thanks for all your help.
  13. External XSLT stylesheets?

    Hey up,Is it possible to kind of modularise XSLT templates, by including other external templates into them? I tried to look for something like this on Google but couldn't find anything...Thanks
  14. External XSLT stylesheets?

    Once again steered me right! Cheers for that.
  15. Hi guys,I'm pretty new to using XSLT for web-page templates. I'm trying to build a very simple stock management application while I learn, and just wondered if somebody could tell me if the XML I have drafted below would work well with an XSLT template or not. <?xml version="1.0" encoding="UTF-8"?><root> <orders> <order id="1" date="2011-05-26 17:20:34"> <items> <product ref="1" quantity="5" /> <product ref="2" quantity="4" /> </items> </order> <!-- and so on... --> </orders> <products> <product id="1"> <title>Product A</title> <stock>1234</stock> <stock_ordered>1000</stock_ordered> <stock_delivery>2011-06-01</stock_delivery> <stats> <total_sold>2344</total_sold> <order_average>32</order_average> </stats> </product> <!-- and so on... --> </products></root> So within the root node, there would be two child nodes for Orders and Products. The idea being the Orders node would obviously contain the order data, and the Products node the product data. I wanted to do it this way to prevent duplicating the product data for each order, and use the "ref" attribute in the Orders->Order->Items product elements to link back to the Products->Product ID attribute.Does this seem like a good idea? Or am I way off?Any help greatly appreciated.Thanks
  16. Proposed XML for XSLT-based templating

    Brilliant, thank you. I'm actually really enjoying learning it. It's been something I've meant to try for a long time, and now I'm glad I did.Thanks again.
  17. Hi guys,I was wondering how when you remove www. from the URL using mod_rewrite, can you preserve the RewriteBase?For example: RewriteBase /qa # Rewrite www. requests RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] When this rewrites the request, "/qa" will be lost. I was hoping to preserve it, so that I don't have to hard-code any paths within the rules.ThanksAdam
  18. New Portfolio Site

    I'm sorry? You asked for a critique and I gave you one. Apologies if it came across overly aggressive, but what's the point in just saying "wow looks amazing"? That's not constructive. I realise I'm not your target audience but you are asking me, as part of the community, for constructive criticism.
  19. Extending a singleton

    Hi guys,A little confused here. Basically I have an abstract Singleton class that I use as a base to provide the getInstance() method, and to track the instances within a static array: abstract class Singleton{ // declare a static array to store instances private static $instances = array(); // declare constructor protected protected function __construct() { } // get the single instance of the called class public static function getInstance() { $class = get_called_class(); if (isset(self::$instances[$class])) { return self::$instances[$class]; } self::$instances[$class] = new $class; return self::$instances[$class]; }} What I'm confused about is, say I have a DB class which extends MySQLi or PDO, how would I extend my DB class to that, but also extend from Singleton?Thanks for any help,Adam
  20. Extending a singleton

    Improved it a little: abstract class Singleton{ // declare a static array to store instances private static $_instances = array(); // declare constructor protected by default protected function __construct() { } // get the single instance of the called class public static function getInstance($class = null) { if (is_null($class)) { $class = get_called_class(); } if (!class_exists($class)) { trigger_error('Unable to return instance of invalid class: ' . $class, E_USER_ERROR); } if (!isset(self::$_instances[$class])) { self::$_instances[$class] = new $class; } return self::$_instances[$class]; } // prevent cloning public function __clone() { trigger_error('Unable to clone classes extending Singleton', E_USER_ERROR); }}
  21. New Portfolio Site

    Whilst it may look nice, there's some major flaws with your website.1) The site is very inaccessible. Most of it's just made up of images, there's very little text for search engines to pick up on. Also with JavaScript disabled your portfolio doesn't even work - JS should only enhance a site, not depend on it to function.2) The user has to download 1.5meg in order to view your site - very possibly a deterrent for anybody with a slower connection. That's mainly down to the images, and not using fairly simple CSS tricks (that you claim to have many years of experience with) to be able to reduce the file sizes drastically. You could also compress the output with Gzip, use sprites, add long-term expire headers to your external resources, move the JavaScript in the <head> to an external file, combine several CSS or JavaScript files together, etc.3) IE7 and less has some issues with your JavaScript portfolio part (the text on the right).Also not such a problem, but why there's such a large gap underneath the website (in FF3.6.13 at least)?In my honest opinion, I think all you know is how to use Photoshop and slice up an image - plus some basic HTML / CSS knowledge.
  22. Changing an array's index

    Well there's no need to store the keys within variables... $arrIndexChange['four'] = $arrIndexChange['two'];unset($arrIndexChange['two']);
  23. Extending a singleton

    Ah, I see. Ideally I wanted to keep the logic of the singleton class within the base class (so as to not have multiple copies of the getInstance() method). What about this as a work around then, just for the cases where I want to extend another class..? abstract class Singleton{ // declare a static array to store instances private static $_instances = array(); // declare constructor protected protected function __construct() { } // get the single instance of the called class public static function getInstance($class = null) { if (is_null($class)) { $class = get_called_class(); } if (isset(self::$_instances[$class])) { return self::$_instances[$class]; } self::$_instances[$class] = new $class; return self::$_instances[$class]; }}class DB extends PDO{ public static function getInstance() { return Singleton::getInstance(get_class()); }} Functionally it works, but is it a bad way to do it?
  24. Which is better for performance

    Hi guys,I was just curious as to which you thought would be the most efficient method of storing friendships.a) One row per relationship. Draw-backs will obviously be when you have to check against 2 columns to retrieve a list of a particular user's friends, or just checking if a certain user is in their friend's list. The returned result set would also be harder to work with. Or, Two rows per friendship. Main draw-back being that twice the memory is needed, and inserting/updating would be a little more complex, however the queries would be much more optimized, and the returned data would be consistent.I'm more included towards b, but what would you say?Thanks for any responses,Adam
  25. Which is better for performance

    Ah that's perfect. I knew of UNION, but never used it enough / read properly into it, for it to come to mind.Thanks for your help!