keeB
-
Posts
1,075 -
Joined
-
Last visited
Posts posted by keeB
-
-
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"`
-
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.
-
You should go with Python so we don't have to answer your dumb questions.
-
Is there a way to use a function for all tables or will i have to make a function for each table?
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 } } ?>
-
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.
-
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.
-
thanks, i guess its all good, since im gonna have to load the data everytime i might as well store it somewhere so no need for cronstuff just yet
Why wouldn't you pull this from a database?
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..
-
My bosses keep adding requirements to this, so my design keeps changing slightly.
That's why.
Less friction when requirements change.
-
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.
-
-
If validation passes:
* Clean Up data ?
* Instantiate Class representing a filled form (ex: User Profile)
* Newly UserProfile object sticks around for duration of session AND passes itself to "StoragePrep" Class, which in turn prepares the data for storage (XML, SQL, etc) and finally passes itself to the corresponding class that will perform the CRUD operations
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.)
-
Good luck
-
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?
-
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
-
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.
-
What you're looking for is this.
public function __set($key, $value) { $this->data[$key][] = $value; }
Or am I missing sometthing?
-
Marking this one so I remember to check it.
Reason I am not answering now is because the question isn't readily apparent.
-
Probably belong in Third Party forums.
-
hey, since your out and about on the forums atm i'd like to bother you with one more question if you don't mind
as far as i understand:
even though you didn't define constructor methods for the InsuranceLead and FinanceLead classes they should in fact have constructors to initialize their private attributes right?
Reason I ask is I was considering using a SimpleFactory design pattern (based on my previous inheritance-based Lead class architecture), but now I'm having second thoughts as to whether it's really necessary, since the Lead class you proposed is at first sight robust enough to carry out any of the tasks the SimpleFactory object would have had to do, in terms of generating leads of a specific strategy... right?
if i'm being vague i'd be happy to explain further but I think you'll get the gist of it
thanks again!
I believe you're talking about the Abstract Factory pattern.
http://en.wikipedia.org/wiki/Abstract_factory_pattern
-
Do you have a problem with reading?
NOW() - INTERVAL 10 HOUR
Wait, what?
-
I think the MVC pattern fits nicely with a forum/discussion board.
-
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)
-
Being a purist, I'm not an __autoload() fan, so I'm not the one to ask.
-
No problem!
I have a hunch that Arrays and Classes are not so different in the internals of PHP.
Which language is best for Social Networking website
in Applications
Posted
I'm glad you lol'd