SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 175
Thread: PHP Retro Style MVC Framework?
-
Sep 22, 2008, 19:12 #1
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Retro Style MVC Framework?
I decided to create a framework that would follow PHP's original 'problem solving' approach. Extensive use of keywords to get what you want instead of object methods... Well, in truth - it works on objects and methods, but I made it in a way that it's accessible from keyworded (global) functions as well.
For example, to create a controller and a view that would show all the posts from the database:
PHP Code:class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts');
render('showposts', $data);
}
}
PHP Code:class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts', array('author' => 'maya'));
render('showposts', $data);
}
}
PHP Code:class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts', null, 10);
render('showposts', $data);
}
}
PHP Code:<? foreach($posts->loop() as $post): ?>
<h1><?=$post->subject?></h1>
<? endforeach; ?>
PHP Code:class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts');
$data['posts'] = combine($data['posts'], 'id', 'comments', 'post_id');
render('showposts', $data);
}
}
PHP Code:<? foreach($posts->loop() as $post): ?>
<h1><?=$post->subject?></h1>
<? foreach($post['comments']->loop() as $comment): ?>
<h1><?=$comment->text?></h1>
<? endforeach; ?>
<? endforeach; ?>)
http://serialize.us/fw/fw.html
Tell me what you think of this kind of work flow, please! I actually really like it. I have been making frameworks for a while not to mention have used codeigniter, cake and symfony in the past, but for some reason I really like this new way here.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 03:36 #2
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Well, instead of us telling you what we think - what do you think of it?
What are the benefits over other frameworks?Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 04:32 #3
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
What application are you using to check your MySQL queries?
It looks very handy - I'm fed up to the teeth of the sluggish PHPMyAdmin.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 04:38 #4
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Doesn't matter - found it.
If anyone's interested it's called MySQL Query browser and can be downloaded in a package with other tools at http://dev.mysql.com/downloads/gui-tools/5.0.htmlJake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 05:01 #5
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yep, it's great. I can't stand PHPMyAdmin. MySQL Query Browser + MySQL Administrator are the best tools for the job (and they're cross platform).
Try creating a new table and see how it creates identities for you, etc. Very convenient.
Right now, BTW, some new features were added.
PHP Code:// find all records from users
find('users');
// find all records from users by name
find('users', array('name' => 'maya'));
// find top 10 records with no filter
find('users', null, 10);
// create and save a new user record
$rec = record('users');
$rec->name = 'maya';
$rec->save();
// find and update a bunch of records
$recs = find('users');
foreach($recs->loop() as $rec)
{
$rec->date = sqldate();
$rec->save();
}
// find and update a single record
$rec = single('user', array('name' => 'maya'));
$rec->date = sqldate();
$rec->save();
// delete this record
$rec->delete();
I think it could be a much better developing experience for most websites. Obviously bigger frameworks would work for huge web applications, but this framework should ultimately allow you to create wonderful dynamic web pages easily (it will come integrated with jquery and fckeditor helpers) .
I also think that a lot of people that are a bit intimidated of OOP could happily use this kind of workflow.
And after all - less typing means less time. Not to mention, it's a lot more readable, as you can see in the example... And it's perfectly functional and flexible.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 05:07 #6
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
I like your way of thinking with how this works, but I'm not so sure on it's efficiency. What are your benchmark results?
Oh, and I've got an idea for your find method:
You have:
PHP Code:find('users', array('name' => 'maya'));
PHP Code:find('users', array('name' => array('maya', 'dave', 'bob')));
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 05:14 #7
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh yeah, excellent idea, I'll add that.
Some tests showed:
Finding records:
Min: 0.00031
Max: 0.00033
Hope that's good enough.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 05:21 #8
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Not bad, not bad at all.
Whilst I don't use frameworks per se, I see a big benefit here in extending a PDO object - if that's what you're doing, I'm sold to the idea.
Being totally honest with yourself - what downfalls can you see here?Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 05:27 #9
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
I'll give you an example of an average joined query and you show me if you can do it with your method:
Code sql:SELECT Teams.Name AS TeamName, COUNT(Goals.ID) AS GoalCount FROM Fixtures INNER JOIN Goals ON (Goals.Fixture = Fixtures.ID AND Fixture = 1) INNER JOIN Players ON Goals.Player = Players.ID INNER JOIN Teams ON Teams.ID = Players.ID GROUP BY Teams.ID
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 23, 2008, 05:28 #10
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok I just added your idea - thanks for it BTW, it's a very good one and works like a charm! And the speed results are exactly the same, as well.
Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 05:31 #11
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm actually not extending from PDO right now but I'll do that when it's coming close to release time. I'll also do a quick fix-up of SQL syntax for SQLITE support.
I made a function for special purposes when neither find() or combine() do the trick, called find_by_query():
find_by_query('table_name', $query);
The thing is, temporary views are not very functional for saving & updating, so find is the only real use for them. Then again, you could use the results from them to fetch records that match what you want and save/update them.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 05:33 #12
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
And as an answer to your question: the main downfall I see right now is very complicated use of multiple DB's. But this framework (at least as my plan says right now) isn't for applications that complex. Even SitePoint works on one database, so you could still make some pretty strong websites with it.
Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 09:06 #13
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
CoderMaya << Intriguing ideas here. Something like this just might get me interested in using frameworks. Will it be open source?
arkinstall << I've been using Query Browser and Administrator for awhile now. phpMyAdmin got too bloated for my taste.
-
Sep 23, 2008, 09:37 #14
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You will want to add some kind of a prefix or suffix to your method names
indexView() or indexAction()
otherwise you will soon run into problems with php reserved function names clashing with what you want for an API (think list)Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
-
Sep 23, 2008, 09:52 #15
- Join Date
- Jul 2008
- Location
- Montréal, Canada
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Very interesting indeed.
Tho the syntax looks a bit like ruby & drupal with the functions. I'd say that the day someone will come with a framework using the drupal way I'll follow for sure!In meanwhile this one sounds interesting. Very simple framework just what you need.
[edit] You plan on adding helper functions and models ?
-
Sep 23, 2008, 10:53 #16
- Join Date
- May 2004
- Location
- Central USA
- Posts
- 806
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, I recently appended a suffix to function names as well in a framework I made due to this very problem. You can't use things like 'list', 'new', 'default', etc. It's quite annoying, as there wouldn't be any scope conflicts within a class definition, but PHP throws a fatal error nevertheless. I ended up having to go with 'indexAction', 'editAction', etc.
Stackbox CMS - Full edit-on-page drag-and-drop CMS
Autoridge - Vehicle information & maintenance part numbers
Twitter | Blog | Online Javascript Compressor
-
Sep 23, 2008, 10:58 #17
- Join Date
- May 2004
- Location
- Central USA
- Posts
- 806
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh - also, on the upside, appending 'Action' on the end of your function names has the added bonus of being able to clearly separate which functions can and cannot be called from the URL in a web browser, giving you the ability to have pseudo-protected functions that are declared as public. This is especially useful when you start getting into more complex tasks where you may have one controller call a function of another controller (like forwarding the action execution to a different part of your application). The function needs to be public to be able to be called outside the class scope from a separate controller, but you don't necessarily want visitors to be able to execute it with a URL.
Stackbox CMS - Full edit-on-page drag-and-drop CMS
Autoridge - Vehicle information & maintenance part numbers
Twitter | Blog | Online Javascript Compressor
-
Sep 23, 2008, 18:10 #18
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Technically, if a method in this framework, or an "action" is not built up properly (ie: a single argument called 'request' - which by the way is a very useful argument in actions) it could not run from the URI.
What I thought about is to actually add an optional suffix like 'Action' that people would use if they can't use what they want, or simply because it's a better way. But I like the idea of keeping an option for simplicity.
I might add an optional 'Controller' suffix, as well.
To answer some questions:
Of course I'll release it with an open source, I'm not gonna encode it.I'm a Linux guy anyway.
An yes, I already included some helpers, models are available already but I'm gonna think about ways to make them really useful with this already simple technique to manipulate data, and I'm gonna add a lot more helpers for many things - but one key thing is that I'm not gonna add any functions that would simply call 1-2 functions there are already available with PHP. This framework should let you use PHP, not make you learn a whole new library. That's the main idea I have for it.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 23, 2008, 18:15 #19
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, optional suffix for controllers and actions - officially added.
Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 24, 2008, 01:24 #20
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Well, Maya, I really think you have something really decent here.
What I'd like to see is this turning to an open-source project. I really have to explore this framework, it's really intriguing - and I'd also love to be a part of this project.
I'm sure most people here agree with me.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 24, 2008, 01:59 #21
- Join Date
- May 2008
- Location
- Kalmar, Sweden
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, from what I've seen it looks very neat. A good idea may be to put it on Google Code and let us contribute
-
Sep 24, 2008, 02:25 #22
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Tidy, very tidy
I will keep an interested eye on this framework Yam, I dont normally like frameworks but I like the way this is coming together.Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Sep 24, 2008, 02:28 #23
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wow haha, I didn't expect this would get so much support. I thought it would just be another tiny idea that's been brought up by me here.
If anyone wants to help - boy I could sure use some to get a decent product of this before I join the army in 2 months. Please PM me with your messenger, google chat or any IM if you want to help me with it and take a look at the current code, my plans, etc...
you can also email me to yamarc@ymail.com (yes ymail)
<3Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 24, 2008, 02:45 #24
- Join Date
- Feb 2008
- Location
- Atlit, Israel
- Posts
- 470
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A few more comments: this is a summary of the main helper functions I have so far (some more more complex, some just helpful):
dump(var) - just like var_dump only it already includes <pre> tags.
void(var) - checks for a null variable, empty array or a false boolean (last is a bit off but decided to include it)
render(name, data) - render a view page (compatible with short tags no matter what your configuration is)
jquery_full_tag() - generate a valid XHTML script tag for embedded jquery and all jquery plugins
jquery_tag() - generate a jquery include tag
jquery_plugins_tag(plugins) - generate an include tag for each jquery plugin from the array
script/style_tag/rsc/rscbin(file) - generate a proper include tag for file. rscbin checks in the public/bin dir.
some more:
link_to(link, name=null, options = null) - build an anchor tag
xhtml_strict/transitional - generate a doctype
redirect - you know
reload - redirect to the current page (prevents POST refresh and can often be useful)
sqldatetime - get current sqldatetime (to insert in record, for example)
sqldate - same only valid for DATE instead of DATETIME
d2dt(date, format = d/m/y h:iA) - get an sql datetime/date in ur preferred format
-- all the db functions - find/single, find/single_by_query, record (create a new Record), query
post, session - get/set global vars. if 1 arg - get, if 2 args - set
timer_start/elapsed - you know
[browser]_says(Str) - replace browser with a name (for example ie,ie6,ie8,ff2,chrome,safari). if the user agent is using the browser in the function name, the string is printed, if not - ... its not
is_[browser] - returns true/false
This is pretty much all the helpers I have so far.Learn about the new Retro Framework
Code PHP the way it was meant to be coded!
-
Sep 24, 2008, 03:09 #25
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Does your dump() function return the dump or just output it?
I'm fed up to the teeth of functions which assume output.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
Bookmarks