Skip to content

Instantly share code, notes, and snippets.

@jdp
Created July 9, 2009 11:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdp/143591 to your computer and use it in GitHub Desktop.
Save jdp/143591 to your computer and use it in GitHub Desktop.
Magneton, the superdense PHP framework
<?php $u=$_GET['u'];$l=$u();extract($l);include("view/{$u}.php");
@jdp
Copy link
Author

jdp commented Mar 31, 2010

The framework that fits in a tweet! Or a vim line.

To use it, write each action of your app in an individual function, and pass the variables you want to send to the view as the return values of the function. For example, app.php:

require 'magneton.php';
function posts() {
  $posts = mysql_fetch_array(mysql_query("SELECT * FROM `posts` LIMIT 20"));
  return array('posts' => $posts);
}

The extract() function brings the associations from an array into the current namespace as variables, and then the view is evaluated in the current namespace. That allows the action's function to pass variables to the view.

And the associated view, view/posts.php:

<div id="posts">
  <?php foreach ($posts as $post): ?>
    <h3><?php echo $post['title']; ?></h3>
    <div class="body"><?php echo $post['body']; ?></div>
  <?php endforeach; ?>
</div>

When http://yourdomain/app.php?u=posts is accessed, the value of $_GET['u'] is treated as a function name and executed. The locals are extracted, and the view is shown. Then, just set up a few rewrite rules and everything's gravy.

I know how insecure it is. It's just a novelty. Oh man please do not deploy this.

@n1k0
Copy link

n1k0 commented Mar 31, 2010

You should check out twitto as well http://twitto.org/

But seriously this is really not secure, I wouldn't encourage anybody using these kinds of stuff in production.

@ppadron
Copy link

ppadron commented Mar 31, 2010

Is it Enterprise-Ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment