Hi all,
If someone wants to change the post's author in the edit/add page you can add these lines of code:
1) In anchor/models/user.php
after row 6 add:
public static function dropdown()
{
$items = array();
$query = Query::table(static::table());
foreach ($query->sort('real_name')->get() as $item) {
$items[$item->id] = $item->real_name;
}
return $items;
}
2) In anchor/routes/posts.php
after row 100 add:
$vars['authors'] = User::dropdown();
3) Edit row 109 adding 'author' in $input
, so the new line is :
Route::post('admin/posts/edit/(:num)', function ($id) {
$input = Input::get(array('title', 'slug', 'description', 'created',
'markdown', 'css', 'js', 'category', 'author', 'status', 'comments'));
4) In anchor/routes/posts.php
after row 198 add:
$vars['authors'] = User::dropdown();
5) Edit row 207 adding 'author' in $input
, so the new line is :
Route::post('admin/posts/add', function () {
$input = Input::get(array('title', 'slug', 'description', 'created',
'markdown', 'css', 'js', 'category', 'author', 'status', 'comments'));
6) Then you can add where you want the dropdown selector in the anchor/views/add.php
and anchor/views/edit.php
:
<p>
<label for="label-author"><?php echo __('posts.author'); ?>:</label>
<?php echo Form::select('author', $authors, Input::previous('author'), array('id' => 'label-author')); ?>
<em><?php echo __('posts.author_explain'); ?></em>
</p>
7) Add the translation entry in anchor/language/en_GB/posts.php
:
'author' => 'Author',
'author_explain' => '',
Now you have a very basic Author selector for every post.