A
A
Anton2015-09-28 08:40:21
Kohana
Anton, 2015-09-28 08:40:21

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',
 ));

Adding news works, everything works in the admin panel. news is visible and can be deleted and edited.
The problem is with the front.
File location.
/application/views/index/ here is the main page of the site v_base.php
/application/views/index/news
v_news_index.php
v_news_get.php
/application/classes/controller/index
news.php
code of this file:
<?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', 'Новости') . " &rarr; ".  $news->title;
$this->template->content = $content;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2015-09-28
Websaytovsky @ws17

Made a route

Route::set('new', 'new(/<id>)', array('alias' => '[0-9]*'))
 ->defaults(array(
  'action' => 'news',
  'directory'  => 'index',
  'controller' => 'news',
 ));

link: http://site/news/get/proverka
how can I hide /get/ in the link through the route
so that it is: http://site/news/proverka

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question