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);
}
}
With filters, for example:
PHP Code:
class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts', array('author' => 'maya'));
render('showposts', $data);
}
}
With a result limit
PHP Code:
class Home extends Controller
{
public function index($request)
{
$data['posts'] = find('posts', null, 10);
render('showposts', $data);
}
}
And in the view
PHP Code:
<? foreach($posts->loop() as $post): ?>
<h1><?=$post->subject?></h1>
<? endforeach; ?>
I also made a pretty way of manually handling relationships in the database.
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);
}
}
and in the view it would be:
PHP Code:
<? foreach($posts->loop() as $post): ?>
<h1><?=$post->subject?></h1>
<? foreach($post['comments']->loop() as $comment): ?>
<h1><?=$comment->text?></h1>
<? endforeach; ?>
<? endforeach; ?>
I made a 5 mins video of it in action (excuse the clumsiness, I'm tired.
)
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.
Bookmarks