Answer the question
In order to leave comments, you need to log in
Kohana 3.1, I can not make the route correctly, how to solve the problem?
In general, I put the addition of news and output at the front.
I add a route, but I can’t go to the page with the news, redirecting to the main one goes.
I'm not routing correctly.
Route::set('news', 'news(/<id>)', array('alias' => '[0-9]*'))
->defaults(array(
'action' => 'news',
'directory' => 'index',
'controller' => 'news',
));
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Index_News extends Controller_Index {
public function before() {
parent::before();
}
public function action_index() {
$news = ORM::factory('new')->order_by('id','DESC')->find_all();
$content = View::factory('index/news/v_news_index', array(
'news' => $news,
)
);
// Выводим в шаблон
if(!empty($new->page_title)){
$this->template->site_name = $new->page_title;
}
if(!empty($new->keywords)){
$this->template->keywords = $new->keywords;
}
if(!empty($new->description)){
$this->template->description = $new->description;
}
$this->template->content = $content;
}
public function action_get() {
$id = (int) $this->request->param('id');
$news = ORM::factory('new', $id);
if(!$news->loaded()){
$this->request->redirect('admin/news');
}
$content = View::factory('index/news/v_news_get', array(
'news' => $news,
));
// Выводим в шаблон
$this->template->title = $news->title;
$this->template->page_title = HTML::anchor('news', 'Новости') . " → ". $news->title;
$this->template->content = $content;
}
}
Answer the question
In order to leave comments, you need to log in
Made a route
Route::set('new', 'new(/<id>)', array('alias' => '[0-9]*'))
->defaults(array(
'action' => 'news',
'directory' => 'index',
'controller' => 'news',
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question