[wp-trac] [WordPress Trac] #11517: Make Admin more MVC-like
WordPress Trac
wp-trac at lists.automattic.com
Tue Aug 24 20:17:00 UTC 2010
#11517: Make Admin more MVC-like
-------------------------------------+--------------------------------------
Reporter: filosofo | Owner: filosofo
Type: enhancement | Status: closed
Priority: normal | Milestone: 3.1
Component: Administration | Version: 3.0
Severity: normal | Resolution: fixed
Keywords: needs-patch admin-theme |
-------------------------------------+--------------------------------------
Comment(by Denis-de-Bernardy):
I'm not entirely sure we can call this fixed. There's a huge difference
between what we're currently doing in WP, and what one would do with a php
framework. Literally copying what's functioning on my localhost:
{{{
*** config.php
Router::connect('/{:controller}/{:action}/{:id:[0-9]+}.{:type}',
array('id' => null));
*** models/Post.php
class Post extends Model {
public $validates = array(
'title' => array(
array('notEmpty', 'message' => 'Title cannot be
empty'),
),
);
}
*** controllers/PostsController.php
class PostsController extends Controller {
public function edit($id = null) {
$id = (int)$id;
$post = Post::find($id);
if (empty($post)) {
$this->redirect(array('controller' => 'posts',
'action' => 'manage'));
}
if ($this->request->data) {
if ($post->save($this->request->data)) {
$this->redirect(array('controller' =>
'posts', 'action' => 'manage'));
}
}
$title = 'Edit post';
return compact('post', 'title');
}
}
*** view/posts/edit.html.php (uses layout.default.php)
<?=$this->form->create($post, array('method' => 'post')); ?>
<?=$this->form->hidden('id'); ?>
<?=$this->form->field('title');?>
<?=$this->form->field('body', array('type' => 'textarea'));?>
<?=$this->form->submit('Edit Post'); ?>
<?=$this->form->end(); ?>
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11517#comment:25>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list