Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. 100 form fields? The only one's who are going to fill that in is you (for testing) and web crawling bots (to ruin your life). 100 form fields is no different in OOP then 5 form fields.
  2. Also, read this: http://propelorm.org/blog/2010/08/03/refactoring-to-propel-1-5-from-peer-classes-to-query-classes.html
  3. We need to see real code, and what you will duplicate, to tell you how you can keep it DRY.
  4. Because I always eat the money I earn... Coins are the hardest to digest, so always round up to a dollar. But what dale said is true, you should not be doing this for free. It depends on how you want to build an application. If you are going the OO way then starting off with the DB design is a bad idea, instead you should start out with your objects and how they will interact with each other to solve the problem domain. Then when you have something that can work, translate this to whatever DB design fits the bill. If you use Doctrine for this, it won't even be that hard. If performance is an issue, you can always adjust your OO design to accomodate for this. Indeed or whatever UML diagramming tool you favor.
  5. Or simply go to http://php.net/?setbeta=1 Its an improvement (in terms of functionality, and usability) over the old website. Visually it looks better, it doesn't need much more IMO.
  6. Strider, you should try to avoid setters/getters as much as you can. abstract class AbstractCalculator { protected $left; protected $right; public function __construct($left, $right) { if ($left instanceof AbstractCalculator) { $left = $left->getValue(); } if ($right instanceof AbstractCalculator) { $right = $right->getValue(); } $this->left = $left; $this->right = $right; } public function __toString() { return (string) $this->getValue(); } abstract public function getValue(); } class Sum extends AbstractCalculator { public function getValue() { return $this->left + $this->right; } } class Multiply extends AbstractCalculator { public function getValue() { return $this->left * $this->right; } } class Divide extends AbstractCalculator { public function getValue() { return $this->left / $this->right; } } echo new Divide(new Multiply(new Sum(5, 5), 2), 10);You should not be forced to edit the same class every time you want to add another operation. Your code becomes bloated because the class needs to do too many things.
  7. So where exactly are you stuck?
  8. Also a client is more likely to hire you if you can show an application where you have built something similar to the project you are discussing. Which is why having demo's of several different kind of applications handy a good sale strategy. Like Kevin already mentioned scout your local businesses, though far from big bucks, they are a good way to fill your portfolio and gain experience. Advertisement is as good a payment as money.
  9. ... the one he wrote himself!
  10. I think you mean <?= which like you say will be always available since 5.4 and are used in Zend views. <? on the other hand won't and may even disappear in the future. http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
  11. It should be noted that <? is discouraged.
  12. I think it would be written in J(arvis)
  13. As an example. By default all images will show a spinner and when the document has been loaded it will fire X number of ajax requests to get the twitter images. You can further improve this with a lazy-loading image script (google that) which means that only when the user scrolls down and the image is "viewed" will it fire the AJAX request. <img src="spinner.gif" alt="" class="load-author-image" data-twitter-screen-name=".."> <script> $(function() { $('.load-author-image').each(function(node) { $.ajax('get-author-image.php', { 'twitter-screen-name': $(node).data('twitter-screen-name') }, function(data) { node.src = data; }); }); }); </script>Additionally you could cache images instead of requesting them over and over again from the Twitter API. Or you could simply use a cron to get the images and store the paths in your database.
  14. The below code should set you off in the right direction <?php $sql = ' SELECT jobs.id, jobs.trackno, jobs.job_start, jobs.job_end, contractors.rate FROM jobs LEFT JOIN contractors ON contractors.id = jobs.contractor_id ORDER BY jobs.id ASC '; $stmt = $mysqli->query($sql); $prev = null; $diff = 0; $totalWorkedHours = 0; while ($job = $stmt->fetch_object('Job')) { if ($prev !== null && ($diff = $job->getJobStartDate()->diff($prev->getJobEndDate())->format('i')) > 30) { // process! // ... // reset! $totalWorkedHours = 0; } echo /* # */ $job->getId(), /* Job# */ $job->getTrackNo(), /* Start */ $job->getJobStartDate()->format('H:i a'), /* End */ $job->getJobEndDate()->format('H:i a'), /* diff */ $diff, /* thisjobtime */ ($workedHours = $job->getWorkedHours()), /* thisblocktime */ $totalWorkedHours, /* + difference */ ($diff / 60), /* + thisjobtime */ $workedHours, /* = thisblocktime */ $totalWorkedHours + ($diff / 60) + $workedHours; $totalWorkedHours += $workedHours; $prev = $job; } class Job { const DATETIME = 'Y-m-d H:i:s'; private $id; private $trackno; private $job_start; private $job_end; private $rate; public function __set($key, $val) { switch ($key) { case 'id': $this->id = $val; break; case 'trackno': $this->setTrackNo($val); break; case 'job_start': $this->setJobStartDate($val, self::DATETIME); break; case 'job_end': $this->setJobEndDate($val, self::DATETIME); break; case 'rate': $this->setJobRate($val); break; default: throw new DomainException; } } public function getId() { return $this->id; } public function setTrackNo($trackNo) { $this->trackno = $trackno; return $this; } public function getTrackNo() { return $this->trackno; } public function setJobStartDate($date, $format = null) { $this->job_start = ($date instanceof DateTime) ? $date : DateTime::createFromFormat($format, $date); return $this; } public function getJobStartDate() { return $this->job_start; } public function setJobEndDate($date, $format = null) { $this->job_end = ($date instanceof DateTime) ? $date : DateTime::createFromFormat($format, $date); return $this; } public function getJobEndDate() { return $this->job_end; } public function setJobRate($rate) { $this->rate = $rate; return $this; } public function getWorkedHours() { return $this->getJobEndDate()->diff($this->getJobStartDate())->format('s') / 3600; } }
  15. I knew a guy once who used the JB signature everywhere. Jason Bannerman?
  16. Unless it's a porn site. Then it's all about the eye-candy. But I guess the design is then considered a feature.
  17. A framework essentially takes out boilerplate code (session, authentication handling, db "abstraction", ..) and allows you to focus on writing the actual application. Some frameworks are really good at this, others just try to get in your way as much as possible just to make sure your really annoyed when working with it. I don't like Laravel, never did, never will. They have a DI container, yet they promote calling all your classes using their static operator, yeah... no! Symfony components are really wasted on them.
  18. There is nothing complex about a forum. At the bare basic you have a Topic and a Post. Everything else are just categories, which in turn can have categories. Instead of starting out with a database schema, try it out in code and populate simple array's, something like this: namespace Forum; class Topic implements Countable, IteratorAggregate { private $posts = array(); public function __construct(Post $firstPost) { $this->addPost($firstPost); } public function addPost(Post $post) { $this->posts[] = $post; } public function receivedReplies() { return ($this->count() - 1) > 1; } public function count() { return count($this->posts); } public function getIterator() { return new ArrayIterator($this->posts); } public function lastReceivedReplyAt() { if (!$this->receivedReplies()) { return null; } $date = end($this->posts)->getPostDate(); reset($this->posts); return $date; } } class Post { private /** @var User */ $author; private /** @var string */ $subject; private /** @var string */ $text; private /** @var \DateTime */ $postDate; private /** @var \DateTime */ $modifyDate; public function __construct($author, $subject, $text, $postDate = null) { $this->author = $author; $this->subject = $subject; $this->text = $text; $this->postDate = $postDate ?: new DateTime; } } class User { private $alias; }
  19. Not exactly. It's a way to separate concerns, your code can still be shitty.
  20. Please consider using spl_autoload_register instead of using __autoload.
  21. Indeed output buffering is not a bad coding practice at all. That said certain PHP installations even have automatic output buffering enabled without having to write ob_start() anywhere. http://be2.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
  22. You need composer Then run: $ php composer.phar installIf that doesn't work then find out where in C:\wamp your php.exe resides copy the path and run it like: $ C:\wamp\php\bin\php.exe composer.phar install
  23. 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
  24. @davidannis, who's your dad?
  25. Exactly. As in your own words:
×
×
  • 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.