Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. $product = new Product(); $product->addReview(1, $auth->getIdentity(), 'B. E. autiful.'); $product->addAward(1, 'Super-Awesome-Comes-Highly-Recommended-stuff'); class Product { public function addReview($productID, $userID, $review) { $review = new ProductReview(); $review->product_id = $productID; $review->reviewed_by = $userID; $review->message = $review; $review->save(); } } class ProductReview { // code }
  2. abstract class O_Abstract { public function getMessage() { } public function getCode() { } } class MyException extends Exception { public function __construct($caller) { $caller->getLogger()->log($caller->getMessage(), $caller->getCode()); parent::__construct($caller->getMessage(), $caller->getCode()); } } throw new MyException($this);
  3. abstract class O_Abstract { protected abstract function throwException($message = '', $code = 0); } class O_Bootstrap extends O_Abstract { protected function throwException($message = '', $code = 0) { $this->getLogger()->log($message, $code); throw new Exception($message, $code); } }
  4. class MyException extends Exception { public function __construct($message = null, $code = 0, Exception $previous = null) { if(Registry::isRegistered('Log')) { Registry::get('Log')->exception($this); } parent::__construct($message, $code, $previous); } } Registry::set('Log', new PHPLog()); try { throw new MyException('Oeps, I did it again!'); } catch(Exception $e) { echo $e->getMessage(); }
  5. You are not extending the class. abstract class Product {} class WineProduct extends Product {}
  6. strip_tags to strip out all HTML tags, it has an optional argument that allows you to tell which should be kept.
  7. About what kind of scripts are we talking here? Personally, I think SaaS is more worthwhile.
  8. $db = Db::factory('mysql://user:pass@host/database'); // get database specific class $db->throwsExceptions(false); // tell the $db object not to throw exceptions $result = $db->query('ERROR'); // query the database, uses Lazy-Loading to connect to the database if($result->isException()) { // were we able to query the database? echo $result->getMessage(); // why not? } $db->throwExceptions(true); try { $result = $db->query('RORRE'); } catch(Exception $e) { echo $e->getMessage(); }
  9. $estimatedSplit=2; $string='foo bar'; echo substr($string, 0, strpos($string, ' ', $estimatedSplit));
  10. Facebook actually uses it's own compiler, calledHipHop. But like thorpe stated PHP scales well for big applications.
  11. class RecursiveFileExtensionFilterIterator extends RecursiveFilterIterator { private $validFileExtensions = array(); public function __construct($recursiveIterator, $validFileExtensions) { $this->validFileExtensions = $validFileExtensions; parent::__construct($recursiveIterator); } public function accept() { return in_array(pathinfo($this->current(), PATHINFO_EXTENSION), $this->validFileExtensions); } } foreach(new RecursiveFileExtensionFilterIterator(new RecursiveDirectoryIterator('.'), array('php')) as $file) { echo $file->getFilename(), "\r\n"; }
  12. Maybe learn PHP first? AbraCadaver already told you how to solve the problem:
  13. Can you give us a description of a regular game? How does it start? How is it played? .. Otherwise the below may work for you: CREATE TABLE Player ( player_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ); CREATE TABLE Match ( match_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, winner VARCHAR(16) NOT NULL ); CREATE TABLE MatchPlayer ( player_id MEDIUMINT UNSIGNED NOT NULL, match_id MEDIUMINT UNSIGNED NOT NULL, health TINYINT NOT NULL, laser_pack TINYINT UNSIGNED NOT NULL, PRIMARY KEY (player_id, match_id) );
  14. file('blah.php?parms') Oeps, I posted this prematurely. Yes, this will only work through HTTP or CLI: php blah.php params1 params2 params3
  15. http://stackoverflow.com/questions/153633/natural-sort-in-mysql Natural sorting is: 1, 2, 10, .. instead of 1, 10, 2, ..
  16. file('blah.php?parms')
  17. You don't have to do a full project to write code. If you want to use a framework for your blog, you can experiment with it. If not, you can get familiar with the different functions in PHP and write your own set of functions (or objects if you are going OO) that you know you will need in your application. If you are planning on allowing people to comment on comments it may be wise to write some function that layers them below one another. Quite possibly you also want to format your dates to a given format, so you'll need a function for that too.
  18. Why is it bad to dependent upon another table? This isn't OO in fact dependencies between tables is a good thing, it's called: data integrity and makes sure no invalid data is entered in your database. Look on other blogs for inspiration, you are obviously missing categories (1 category, many posts) and tags (many tags, many posts). If people are uploading stuff you probably want to know who uploaded what? People can comment on your posts, even comment on comments. Who created the post, who edited it, who is currently editing it, .. enough stuff to think about. Did you get a course into normalization? Sit down, put everything in one table, find repeating groups, and remove anomalies.
  19. The username in post_data should be user_id and a reference to users (user_id). Choose your data types more appropriately. Do you seriously need space for 2 billion users? If your password is hashed you'll probably want something like CHAR(32) or CHAR(40). For e-mail address VARCHAR(96) should suffice and avatar_url VARCHAR(128), date & time should be combined in a more descriptive column: posted_at DATETIME post_data should be TEXT or if you are running MySQL 5.0.3+ you can declare VARCHAR(512) for example if you need that many characters. Your database design clearly hasn't been thought through as many of the things you mentioned aren't modeled in it.
  20. $this->db->like('categories','Politics'); $this->db->or_like('categories','History');
  21. If this is just some service where you signed up for your own free forum, getting support may become problematic.
  22. Or add the FILE_IGNORE_NEW_LINES flag.
  23. It depends on the task/application. I write crawlers in procedural for example as OOP would be too much overhead.
  24. Could you post those 5/6 queries? Generally though you shouldn't need a separate file for each query as you can wrap these in functions that can be called whenever needed.
  25. He meant PHP Get yourself a book on PHP, do a search on this forum you'll find some threads with extensive lists on them. Don't try to create your forum in one-go but instead create several components that will give you the required knowledge to write your forum one day. A contact form, a guestbook, paginate results, registration, login, profile editing, content searching, get result from a database and apply a template, ..
×
×
  • 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.