Hey.
Im using Contentify 2.0 and its working so far but i cant see my published news / pages. http://imgur.com/a/uxLBB
Any ideas?
Hi,
Im using Contentify 2.0 too and i have no problem,
Can you copy paste your NewsController, routes.php and Model News.php please i will compare with me.
Routes.php
```
ModuleRoute::context('News');
ModuleRoute::resource('admin/newscats', 'AdminNewscatsController');
ModuleRoute::get(
'admin/newscats/{id}/restore',
['as' => 'admin.newscats.restore', 'uses' => 'AdminNewscatsController@restore']
);
ModuleRoute::post('admin/newscats/search', 'AdminNewscatsController@search');
ModuleRoute::resource('admin/news', 'AdminNewsController');
ModuleRoute::get(
'admin/news/{id}/restore',
['as' => 'admin.news.restore', 'uses' => 'AdminNewsController@restore']
);
ModuleRoute::post('admin/news/search', 'AdminNewsController@search');
ModuleRoute::get('news', 'NewsController@index');
ModuleRoute::get('news/{id}/{slug?}', ['as' => 'news.show', 'uses' => 'NewsController@show'])
->where('id', '[0-9]+');
ModuleRoute::get('news/{slug}', 'NewsController@showBySlug');
ModuleRoute::get('news/showStream/{timestamp?}', 'NewsController@showStream')->where('timestamp', '[0-9]+');
ModuleRoute::post('news/search', 'NewsController@search');
NewsController.php
use App\Modules\News\News;
use App\Modules\Videos\Video;
use View, Request, DB, URL, HTML, FrontController;
class NewsController extends FrontController {
public function __construct()
{
$this->modelName = 'News';
parent::__construct();
}
public function index()
{
$this->indexPage([
'buttons' => null,
'tableHead' => [
trans('app.title') => 'title',
trans('app.category') => 'newscat_id',
trans('app.date') => 'created_at'
],
'tableRow' => function($news)
{
return [
raw(HTML::link(url('news/'.$news->id.'/'.$news->slug), $news->title)),
$news->newscat->title,
$news->created_at
];
},
'actions' => null,
'filter' => true,
'permaFilter' => function($query)
{
return $query->published();
}
], 'front');
}
/**
* Show the preview of multiple news
*
* @return void
*/
public function showOverview()
{
// Internal news are protected and require the "internal" permission:
$hasAccess = (user() and user()->hasAccess('internal'));
$newsCollection = News::published()->where('internal', '<=', $hasAccess)->filter()
->orderBy('created_at', 'DESC')->take(5)->get();
$this->pageView('news::show_overview', compact('newsCollection'));
}
public function showStream($offset = null)
{
if ($offset) {
$offset = (int) $offset;
} else {
$offset = time();
}
$offset = DB::raw('FROM_UNIXTIME('.$offset.')');
$colums = 2;
$rows = 3;
$limit = $colums * $rows;
$streamItems = [];
/*
* News
*/
$hasAccess = (user() and user()->hasAccess('internal')); // Internal news are protected
$newsCollection = News::published()->where('internal', '<=', $hasAccess)->where('updated_at', '<', $offset)
->orderBy('updated_at', 'DESC')->take($limit)->get();
foreach ($newsCollection as $news) {
$news->itemType = 'news';
$streamItems[] = $news;
}
/*
* Videos
*/
$videos = Video::where('updated_at', '<', $offset)->orderBy('updated_at', 'DESC')->take($limit)->get();
foreach ($videos as $video) {
$video->itemType = 'video';
$streamItems[] = $video;
}
/*
* Sort the stream.
* NOTE: All items need to have the updated_at timestamp attribute!
*/
usort($streamItems, function($itemOne, $itemTwo)
{
return ($itemOne->updated_at->timestamp > $itemTwo->updated_at->timestamp) ? -1 : 1;
});
$oldSize = sizeof($streamItems);
$streamItems = array_slice($streamItems, 0, $limit);
$more = (int) ($oldSize > sizeof($streamItems));
if (Request::ajax()) {
return View::make('news::show_stream_ajax', compact('streamItems', 'more'));
} else {
$this->pageView('news::show_stream', compact('streamItems', 'more', 'limit'));
}
}
/**
* Show a news
*
* @param int $id The ID of the news
* @param string $slug The unique slug
* @return void
*/
public function show($id, $slug = null)
{
if ($id) {
$news = News::whereId($id)->published()->firstOrFail();
} else {
$news = News::whereSlug($slug)->published()->firstOrFail();
}
$hasAccess = (user() and user()->hasAccess('internal'));
if ($news->internal and ! $hasAccess) {
return $this->alertError(trans('app.access_denied'));
}
$news->access_counter++;
$news->save();
$this->title($news->title);
$this->openGraph($news->openGraph());
$this->pageView('news::show', compact('news'));
}
/**
* Show a news by slug instead of ID
*
* @param string $slug The unique slug
* @return void
*/
public function showBySlug($slug)
{
$this->show(null, $slug);
}
public function globalSearch($subject)
{
$newsCollection = News::published()->where('title', 'LIKE', '%'.$subject.'%')->get();
$results = array();
foreach ($newsCollection as $news) {
$results[$news->title] = URL::to('news/'.$news->id.'/show');
}
return $results;
}
}
News.php
use SoftDeletingTrait, ContentFilter, DB, OpenGraph, Comment, Rss, Config, Lang, URL, BaseModel;
class News extends BaseModel {
use SoftDeletingTrait;
protected $dates = ['deleted_at', 'published_at'];
protected $slugable = true;
protected $fillable = [
'title',
'summary',
'text',
'published',
'published_at',
'internal',
'enable_comments',
'newscat_id',
'creator_id'
];
protected $rules = [
'title' => 'required|min:3',
'published' => 'boolean',
'internal' => 'boolean',
'enable_comments' => 'boolean',
'newscat_id' => 'required|integer',
'creator_id' => 'required|integer',
];
public static $relationsData = [
'newscat' => [self::BELONGS_TO, 'App\Modules\News\Newscat'],
'creator' => [self::BELONGS_TO, 'User', 'title' => 'username'],
];
public static function boot()
{
parent::boot();
self::saved(function($news)
{
self::updateRSS();
});
self::deleted(function($news)
{
self::updateRSS();
});
}
public function scopeFilter($query)
{
if (ContentFilter::has('newscat_id')) {
$id = (int) ContentFilter::get('newscat_id');
return $query->whereNewscatId($id);
}
}
/**
* Select only news that have been published
*
* @param Builder $query
* @return Builder
*/
public function scopePublished($query)
{
return $query->wherePublished(true)->where('published_at', '<=', DB::raw('CURRENT_TIMESTAMP'));
}
/**
* Count the comments that are related to this news.
*
* @return int
*/
public function countComments()
{
return Comment::count('news', $this->id);
}
/**
* Create an instance of OpenGraph that represents Open Graph tags.
*
* @return array
*/
public function openGraph()
{
$og = new OpenGraph(true);
$og->title($this->title)
->type('article')
->image($this->newscat->uploadPath().$this->newscat->image)
->description($this->summary)
->url();
return $og;
}
/**
* Create/update RSS file
*
* @return void
*/
public static function updateRSS()
{
$feed = Rss::feed('2.0', 'UTF-8');
$feed->channel([
'title' => Config::get('app.title').' '.trans('app.object_news'),
'description' => trans('news::rss_last'),
'language' => Lang::getLocale(),
'link' => Config::get('app.url'),
'lastBuildDate' => date('D, j M Y H:i:s ').'GMT'
]);
$newsCollection = News::published()->orderBy('created_at', 'DESC')->take(20)->get();
foreach ($newsCollection as $news) {
$url = URL::route('news.show', $news->id);
$feed->item([
'title' => $news->title,
'description|cdata' => $news->summary,
'link' => $url,
'guid' => $url,
'pubDate' => date('D, j M Y H:i:s ', $news->created_at->timestamp).'GMT'
]);
}
$feed->save(public_path().'/rss/news.xml');
}
}
```
How many news are you ?
Do you have one news published ?
What is your URL address ?
Im able to write news or to make a new page. They're also saved in my admin backend but arent displayed on the site itself. When i click on the news in the admin panel im getting the error i posted in my first post.
Okay, i fixed it.
Removed / Purged Apache2 then reinstalled it and rebooted my server. Working now.^^
Very strange ^^ maybe cache problem
Not sure. I made sure to clear cache, views etc. I thought maybe its a webserver problem because i tried everything else but it didnt work. In the end a friend of mine said: "Did you try to reboot the server?" and yea, there was the fix. lol
Most helpful comment
Not sure. I made sure to clear cache, views etc. I thought maybe its a webserver problem because i tried everything else but it didnt work. In the end a friend of mine said: "Did you try to reboot the server?" and yea, there was the fix. lol