Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. I think a simple search would reveal a lot of tutorials related to PHP CMS. Writing a simple CMS is not even that hard. Try to create a guestbook and you pretty much already have much of the required knowledge to write a simple CMS. You would need a <form/> that will hold your data: title, content. If you don't know HTML then find a tutorial that explains to you how you can create forms. And a tutorial that explains how you process a form with PHP maybe write the information you posted back out on the screen. Then a simple tutorial that explains you how to write/read stuff from a database and you have all the knowledge needed for your simple CMS. Then extend on that and learn about: - authentication and build a login for your CMS and secure your pages - mod_rewrite and create friendly URL's like /en/how-i-learned-mod-rewrite
  2. @davidannis, who's your dad?
  3. Exactly. As in your own words:
  4. We're a help forum and any decent programmer that would be able to provide an advanced topic is able to solve it himself and does not require any help, or knows how to find it without having to resort to a slow medium like a forum. So by definition we are a tutoring platform for newbie programmers. Even SO has this problem. Although their traffic is way above ours, the number of advanced topics that would pass there on a day is close to a few to none. What would we be sparring about? The best solution to a question asked on the forum? The better explanation? The better "go-fuck-yourself" answer? I don't think AOP solves anything. It gives you the illusion of not having dependencies while they are simply lurking in the dark. If I need logging I simply add a LoggerAwareInterface and DI does the rest. And if there is some cross-cutting concern with a dependency that could hinder re-use I can always use a Proxy (which is btw how the better AOP frameworks operate). "No object lives in isolation" and you can have loosely-coupled objects but you can't have anything beyond that point besides the illusion you do.
  5. I agree entirely with what you said, and it's also what I meant in my previous post that an "intelligent setup", as you put it, is the goal. But you answered your own question then, unless I missed your argument for __set/__get in your previous post?
  6. Besides there is no magic necessary: class Photograph extends SplFileInfo implements ImageInterface { private $width; private $height; private $mimeType; public function __construct($filename) { list($this->width, $this->height) = $image = getimagesize($filename); $this->mimeType = $image['mime']; parent::__construct($filename); } public function getWidth() {} public function getHeight() {} public function getMimeType() {} } interface ImageResizeStrategy { public function resize(ImageInterface $image); } class FixedResize implements ImageResizeStrategy { .. public function resize(ImageInterface $image) { .. } } class ProportionalResize implements ImageResizeStrategy { .. public function resize(ImageInterface $image) { .. } }
  7. Any kind of magic in your app is bad, I think everyone agrees on that and when you can avoid it, you should. Like overloading operators in C++ and Ruby. At some point it bites you. And when you really need to, you should properly document it (@property, @method). To use your example, in this particular case (which is a pretty bad use of __set and __get yet ever so popular) you would end up with a lot of code for each supported property inside __set and __get (possibly making each method extend beyond what you can fit on your screen, which should be a clear indication something is wrong) and each time your class would need more properties you would have to dig into that already messy code and extend it and hope you don't break anything in the process. Basically you end up emulating what OO provides out of the box. Also __set and __get are PHP4 artifacts which are since PHP5 replaced by proper interfaces ArrayAccess and Serialize for __sleep and __wakeup.
  8. users (user_id, ..) inventory (user_id, item_id, loc_row, loc_col) items (item_id, width, height)Your item should have a width/height expressed in the number of rows/cols it consumes. Then knowing your inventory is n1 x n2 you can simply calculate whether the selected location fits inside your grid. To display the grid you would first have to create the grid, and float the item over it at the specified position of loc_row. Using js you can make it snap to the grid lines.
  9. MVC is a pattern, not anything you listed above. Some of them implement it, though like Zend, Symfony, CakePHP, and CodeIgniter. Joomla and Drupal are CMS systems, and Twitter Bootstrap is a CSS framework. Zend and Symfony are good investments to learn, as is Twitter Bootstrap and Drupal.
  10. Zoals al eerder vermeld kan je best je vraag in het Engels stellen. I strongly advice you to buy a book on PHP, preferably in English as this solves most of the problems you currently face.
  11. Like Muddy already said you need a User class, the registered state is nothing more but to check if the user has an ID or not.
  12. Dit forum is enkel Engelstalig dus weinigen zullen je dan ook hier kunnen helpen in het Nederlands. Ik raad je dan ook aan om je post te vertalen naar het Engels. As for your question you need to read the XML results into an array and group them according to week.
  13. SplFileObject combines all file operations.
  14. Yes, there is a big difference. utf8_bin compares string in binary (as in byte-by-byte instead of character-by-character), so sorting may return weird results. Since a and A both have different byte codes, one could say it is case sensitive. utf8_general_ci is case insensitive character-by-character comparison which is probably what you want. More information here: https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-sets.html
  15. You need JavaScript to generate the input boxes, though jQuery will be simpler to use. // credits: http://stackoverflow.com/a/10142256 Array.prototype.shuffle = function() { var i = this.length, j, temp; if ( i == 0 ) return this; while ( --i ) { j = Math.floor( Math.random() * ( i + 1 ) ); temp = this[i]; this[i] = this[j]; this[j] = temp; } return this; } var playerNames = ['Mike', 'Joe', 'Ken', 'Barbie', 'John'], // add up to 100 names here totalPlayers = 5, // number selected by the user htmlStr = '', tpl = '<div><label for="{id}">{label}</label><input type="text" id="{id}" name="names[]" value="{name}"></div>'; playerNames.shuffle().slice(0, totalPlayers).forEach(function(name, i) { htmlStr += tpl.replace(/\{id\}/g, 'player' + i) .replace(/\{label\}/g, 'Player #' + i) .replace(/\{name\}/g, name); }); $(htmlStr).appendTo('#playersForm');When you submit the form you will be able to access the names in PHP as: $names = $_GET['names']; print_r($names);
  16. You stare yourself blind on OOP. There is no such thing as a good OOP practice. There are only good practices and bad practices. When you have a small system it is a bad practice IMHO to create a very complex domain model for no other reason then "because it's true OO". Remember this quote? When developing software you have to consider the bigger picture and when a simpler method presents itself you do best to take it. Ask any industry expert, hell ask Martin Fowler himself, and they will tell you that when you can keep it simple, you keep it simple! But I get it you are an eager student with no industry experience and you like OOP, as do I. But consider that at some occassions you just may be wrong. And if you can't/won't accept that, then the industry will teach you when you are fired because you made it so complex that even you can't figure it out anymore. But hey.. it's true OO, right?
  17. $lines = file("logs/accesslog.txt"); for ($pos = count($lines) - 1, $end = $pos - 6; $end < $pos; $pos--) { echo $file[$pos], '<br>'; }
  18. Great so when you receive their input you intval it and use that to query your database. As you can see my answer contained a link, follow it and read what the page says.
  19. Your opinion does not resemble the general consensus.
  20. Leave the number stored in your database as 1 and use str_pad to pad the number with the leading zero's when you display it. And if you really need it change your data type to varchar or if it has a fixed length char. Why would you let your customers go through the extra trouble of padding with 0's? mysql_num_rows > 1 Pass them as a query string with an incremental page number: search.php?page=2&mrn=1 In your query then you need to convert the page to an offset. For example if you limit the results to 20 per page. function page_to_offset($page, $count) { return ($page - 1) * $count; } $count = 20; $offset = page_to_offset($_GET['page'] ?: 1, $count); $sql .= ' LIMIT ' . $count . ' OFFSET ' . $offset;For the first page this will look like: Page 1: LIMIT 20 OFFSET 0 Page 2: LIMIT 20 OFFSET 20
  21. Your logged_in() function does nothing. So your else part will always execute. I also believe you don't want to compare your username to true unless you want to make sure it's not empty or something. function logged_in() { return !empty($_SESSION['username']); }
  22. Don't write functions like that. The if/else only adds noise to what you really want to say (you are logged if you pass foo). Instead write them like: function isLogged($var) { return $var == 'foo'; }Which outputs the exact same thing.
  23. ignace

    PHP Classes

    Was my comment really that offensive? Nothing in my post was untrue, flat-file is incredibly slow due to disk read/seeks. If your data set is small you can store it all in memory, you can't beat that with a flat-file. I do. I didn't call you names nor did I have to resort to the F word. I called you on Becuase it is not true.
  24. ignace

    PHP Classes

    Clearly you then have no idea about the possibilities/workings of a database. I, and many others on this forum, can beat your flat-file solution where your application will look like a slug crossing the road and ours the rabbit running loops around you.
  25. If you don't take it from me, read this: http://stackoverflow.com/a/16400738
×
×
  • 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.