Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. product (product_id); product_color (product_color_id); product_size (product_size_id); product_quantity (product_id, product_color_id, product_size_id, quantity);
  2. I don't see why you need a utility class that holds the alphabet as a static variable. The alphabet isn't likely to change any time soon. Since you supposedly need this I think you haven't yet identified certain models or thought well about your OO-design.
  3. In your specific instance you could have: spl_autoload_register(array('LibraryAutoloader', 'autoload')); spl_autoload_register(array('ApplicationAutoloader', 'autoload')); So that instead of having to add yet another if to your __autoload each new module can have it's own autoloader without having to modify any code. You should avoid static methods as much as possible as this is procedural programming and not true OO. This actually hurts re-usability. Better would be to use a setup like Zend where there is a class for each item so that Form's and Model's can use validation/filtering. $form->addValidate('username', new Zend_Validate_Username()); $model->addValidate('username', new Zend_Validate_Username());
  4. Or store the image in your DB, very handy if it turns out your hosting company only creates back-ups of the DB files.
  5. If you are hiding the correct possible answers in your HTML then everyone with some HTML knowledge will be able to answer your questions correctly. Let the user enter the answer match that in PHP with the correct possible answers synchronously (reload the page) or asynchronously (AJAX, reload part of a page).
  6. Meet the method argument list: $model->test($form);
  7. function __autoload($class_name) { include $class_name . '.php'; } You should take a look at spl_autoload_register as this allows you to use an OO-approach to autoloading. class controller extends mysql A Controller does not extend MySQL. Such implementation details should be abstracted so that your application becomes not dependent on the presence of any specific extension/technology. class model A Model is not explicitly named Model, it's a concept. If you have ever programmed an application where you would have a file like contact.php that did the processing and called a separate file for all HTML-related stuff then you have programmed an MVC-architecture (sorta). The Controller is responsible for all Application-logic (POST, GET, ..), the Model lives in the Domain-layer and is responsible to enforce business rules (eg login after verification) and use some data store to persist information, the View has the only responsibility of showing stuff (not do any real work).
  8. I do not only have the codes, I can even see them: 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101 000001110001001010000101010001010101010101010101010101010101010 100101000010101000101010101010101010101010101010101001010010101 111000100101000010101000101010101010101010101010101010101010101
  9. I am more clever then I appear
  10. Try this: function post($url, array $data) { // http://www.php.net/manual/en/context.http.php $config = array( 'method' => 'POST', 'content' => http_build_query($data), 'ignore_errors' => true ); $stream = stream_context_create($config); $response = file_get_contents($url, false, $stream); $reader = new XMLReader(); $reader->xml($response); return $reader; } $xmlReader = post('http://domain.top/resource', array('foo' => 'bar'));
  11. strip_tags (it also has an optional list to allow certain tags)
  12. Untested function post($url, $content) { // http://www.php.net/manual/en/context.http.php $config = array( 'method' => 'POST', 'ignore_errors' => true ); $stream = stream_context_create($config); $fopen = fopen($url, 'r+', false, $stream); $response = ''; fwrite($fopen, http_build_query($content)); while($chunk = fread($fopen, 1024)) { $response .= $chunk; } fclose($fopen); $reader = new XMLReader(); $reader->xml($response); return $reader; }
  13. $controller = getParam('c', $_GET); switch($controller) { case 'about': include 'about.php'; break; case 'contact': include 'contact.php'; break; default: include 'home.php'; break; } function getParam($offset, &$array, $default = null) { if(array_key_exists($offset, $array)) { return $array[$offset]; } return $default; } Is a (very) simple example of MVC. What level of framework are you looking for? CodeIgniter (easy) Symfony (medium) Zend (hard)
  14. class OnePlusOneSimpleEchoInPhp { const STDOUT = 'php://output'; const OUTPUT = '1+1'; public static function output() { file_put_contents(self::STDOUT, self::OUTPUT); } } OnePlusOneSimpleEchoInPhp::output(); I think this is the simplest example I could think of how to do this effectively
  15. You should create a new entry for each answer given by the user. UserResult (question_id, answer_id) But like I already said, you should mind the edge-cases.
  16. preload images is about the only critic I have
  17. list(,$domain) = explode('@', $email); $domain = mysql_real_escape_string($domain); $domainsearch = mysql_query("SELECT domains FROM allowedDomains WHERE domains LIKE '$domain'"); $returnedrows = mysql_num_rows($domainsearch); if ($returnedrows<=0 ){ $err=$err."You must enter an acceptable email address";
  18. http://img683.imageshack.us/i/scrnshotwin7ff3613.png/ I'm using Windows 7 Ultimate and Firefox 3.6.13
  19. Quiz (id, ..) Question (id, quiz_id, ..) Answer (id, question_id, is_correct_answer, ..) You should also think about edge-cases, like: what if a user removes an answer, or rephrases it?
  20. list(,$domain) = explode('@', $email);
  21. You don't need to store it back into the array. The array will still be intact after you looped over it So like BlueSkyIS showed extract will be fine.
  22. I understand your point I've cursed at it myself in college when the teacher went all high-tech with his ... globals ... And setters/getters for each and every class variable because that's what encapsulation means, right? Be realistic, all employers want A-grade employees but they'll usually settle for far less because well .. it turned out he already worked at Google. Their is a serious demand of programmers and each year that demand grows so to make sure they won't be paying programmers like rock-stars they even settle for the office clerk down the hall .. he once talked to a programmer .. They taught me wrong, like I showed ^ up there ^ but I turned out alright, didn't I? ... FORTRAN will rule the world ... Yes and for that you pay 80K+ per year (plus expenses).
  23. It depends on the Quiz you are trying to make. If it's a typical Question and select from multiple possible Answers then a normal Question/Answer set-up will do. However, if you are after creating a Quiz that allows to make a Question but the Answer can be text as well as only a text input field then you will be required to go for a different approach.
  24. I disagree. You can't always choose where you go to college and these people deserve the same fair chance as you did. I concur. The degree is a guarantee towards your employer (and yourself, if you are not keen on staying current). http://content.screencast.com/users/DeviousDan/folders/Jing/media/7ffbf000-b6c2-4aac-bba3-ffc4581a6af1/2011-01-08_1848.png Showing off examples do not make your point any stronger. A college teaches you the basics and assumes the future and the company you work for will shape you. They give you the paper, but it's you who eventually paint the masterpiece.
  25. That's because the path is relative to the script that called it. So if index.php includes Database then the database class has to include constants relative from index.php hence why it's desired to use an absolute path when working with multiple calling scripts.
×
×
  • 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.