Jump to content

keeB

Staff Alumni
  • Posts

    1,075
  • Joined

  • Last visited

Everything posted by keeB

  1. First, let me commend you for relasing your TinyMVC to the the wolves. Releasing your code, knowing that developers like to scrutinize, is a great achievement! Since there isn't an API documentation I was left looking at the twitter implementation. I'm impressed, there's no doubt about the amount of time and effort you put in to the code and I would think it would serve as a great addition to the portfolio/resume. Some questions, comments, etc. 1. Can you pass parameters to the methods in your Controller? I noticed in some places in controllers/twitter.php I was thinking.. 'this would benefit from having a parameter or two' (check the user_timeline() function. 2. I assume setting $this->data['content'] is what actually gets the page displayed. Do you think having a method in the core.php called something like 'render' would help? I think it would help your syntactic sugar and make things a bit more readable. 3. What does the hooks() function do? My only gripe was I had to convert all of your files to UNIX format. Saving them in DOS (\r\n) makes it hard to read on my pretty terminals keeb@deviL:~/micromvc-php-read-only$ perl -pi -e 's/\r\n/\n/;' `find . -name "*.php"`
  2. I commend you for wanting to learn. Experience comes from not only learning, but putting what you learn to good use which causes you to understand what you've learned.
  3. You should go with Python so we don't have to answer your dumb questions.
  4. Your question, unfortunately, shows a fundamental lack of programming knowledge. Jumping in to OO-Development with such a basic skill set will cause more harm than good, in my opinion. While it's always great to branch out and learn a diverse programming vocabulary, you should start with gaining some experience first. To answer your question, it depends on what you're trying to accomplish. If you want to write a function which loads, say, session data related to a user, it could be categorized as 'have[ing] to make a function for each table' However, the real question is, how are you executing this query? Do you do it like this? (Functional) <?php $conn = mysql_connect("localhost", "user", "pw"); mysql_select_db("some_db"); function get_session_data($conn, $userid) { # $conn is the db connection we're using $q = mysql_query("select sessiondata from user", $conn); while($row=mysql_fetch_row($q)) { // do something with the result set } return $data } ?> Or like this? (Functional and a bit more structured) <?php function query($query, $conn) { //build an array of results. $ret = array(); # to be populated and returned $q = mysql_query($query, $conn); while($row=mysql_fetch_row($q)) { $ret[] = $row; //add to the $ret array. } return $ret } function get_session_data($user_id) { $res_array = query("select sessiondata from user where userid ='$user_id'"); $data = $# get some data.... return $data } ?> Or like this? (OOP) <?php class Database { private $connection; public function __contruct($host, $username, $password, $database) { $this->connection = mysql_connect($host, $username, $password); mysql_select_db($database, $connection); } public function query($q) { //build an array of results. $ret = array(); # to be populated and returned $q = mysql_query($query, $this->connection); while($row=mysql_fetch_row($q)) { $ret[] = $row; //add to the $ret array. } return $ret } } class User { private $db_conn; public function __construct() { $this->db_conn = new Database("localhost", "user", "pw", "some_db"); } public function get_session_data() { $this->db_conn->query("select sessiondata from user where userid = '$user_id'"); // do something with the data.. return $data } } ?>
  5. I wonder if you could write your own extension. A quick look at the documentation lead me here: http://phing.info/docs/guide/current/chapters/ExtendingPhing.html#WritingTasks Very interesting software.
  6. header.php: <html> <head> // some header information here </head> main.php include("header.php"); // do some body stuff here include("footer.php"); Doesn't belong here.
  7. overhead? i'd hate to have to query the db every time someone new visited the site... how about caching or serializing the query? or maybe reading from XML or something... better for a small amount of data and concurrent reads afaik! Ever been to Google? You know when you type in their box, and they do an auto complete, those are database hits? You know when you go to Ebay, and search for anything, there's tons of database hits? You know most Oracle/Postgres databases can hit hundreds of thousands of transactions per second? Overhead. lol..
  8. That's why. Less friction when requirements change.
  9. I would assume the set methods in your object would be sanitized on Input if coming from a Form. In cases where this cannot be guaranteed (you better have a good reason) enforce the validation in the actual Set method itself.
  10. Here are some links: http://en.wikipedia.org/wiki/Data_Access_Object http://en.wikipedia.org/wiki/Object-relational_mapping
  11. You should be passing a Model object to your Persistence layer. How your 'StoragePrep' knows what to do with said Model object is up for debate. You can use the PHP Reflection API, but most frameworks use XML or YAML as a mapper. Example of a model object <?php interface Entity { function returnSetList(); function returnGetList(); } class Person implements Entity { private $firstName; private $lastName; public function setFirstName($name) { $this->firstName = $name; } public function setLastName($last) { $this->lastName = $last; } public function getFirstName() { return $this->firstName; } public function getLastName() { return $this->lastName; } public function returnSetList() { return array("setFirstName", "setLastName"); } public function returnGetList() { return array("getFirstName", "getLastName"); } } ?> Normally, there are helpers that exist for model objects known as DAO's. You can think of these as factory's of Model objects. Here's an example: <?php class BaseDao { public function saveEntity( Entity $entity) { $func_list = $entity->returnGetList(); $list = array(); // hold the values in an array (this is dumb but here for reference) foreach ($func_list as $function) { $list[] = call_user_func($entity, $function); } //inspect the list and do something with it. } } class PersonDao extends BaseDao { public function savePerson(Person $person) { if ($person != null) saveEntity($person); } } ?> I typed that on a whim, but that is how I would do it via Reflection (or something similar.)
  12. Well............... You would then go 1 step further and implement a Field_Values table, which has a FK of FieldId. For a Selector, you'd have multiple values for a single field. Make sense?
  13. I have thoughts. Your idea is not good Form | form_id | field_id (FK) | name | action | Field | field_id | type (TEXT, CHECK, SELECTOR) | value Much more elegant
  14. It sounds like you need to go back to the drawing board to understand the desires behavior of your template engine. If you have the existing (which work) cases in mind, and take this one in to consideration, you may come out with something much more simple and efficient. At least, it makes much more sense going back to the beginning than to try to impose a bandage in to a system that isn't conducive to it. We generally call those 'hacks' for good reason.
  15. What you're looking for is this. public function __set($key, $value) { $this->data[$key][] = $value; } Or am I missing sometthing?
  16. Marking this one so I remember to check it. Reason I am not answering now is because the question isn't readily apparent.
  17. Probably belong in Third Party forums.
  18. I believe you're talking about the Abstract Factory pattern. http://en.wikipedia.org/wiki/Abstract_factory_pattern
  19. I think the MVC pattern fits nicely with a forum/discussion board.
  20. We're both Human I made the mistake of misinterpreting what you said before. You're right, there's no way to safeguard from having a orphaned entry in a many-to-one situation where you're deleting all of the 'many' I suppose, the way I have always thought about it was to delete the 'one' and have the CASCADE triggers delete everything downstream. Thinking on it further, I don't think, at least in this particular case, that there should be an issue. Meaning, if a user is deleted, I do not think it should impact the other users history (losing auditing because a relationship was severed)
  21. No problem! I have a hunch that Arrays and Classes are not so different in the internals of PHP.
×
×
  • 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.