Так и не решил задачу...
Создал единый коммон для авторизации и сессий
Код:
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Controller_Auth extends Controller {
protected $auth;
protected $user;
protected $session;
public function before() {
parent::before();
$this->auth = Auth::instance();
$this->user = $this->auth->get_user();
$this->session = Session::instance();
}
}
Его непосредственно наследует коммон который работает как главный шаблонизатор.
Код:
<?php defined('SYSPATH') or die('No direct script access.');
//Базовый контроллер
abstract class Controller_Common extends Controller_Auth {
public $template = NULL;
public function before()
{
parent::before();
$this->template = View::factory('Public/Template');
$siteurl = Kohana::$config->load('configsite.url');
$sitetitle = Kohana::$config->load('configsite.sitetitle').'::';
$login = Request::factory('Chunks_Login/index')->execute();
$this->template->siteurl = $siteurl;
$this->template->sitetitle = $sitetitle;
$this->template->description = '';
$this->template->keywords = '';
$this->template->stylesheet = '';
$this->template->javascriptlib = '';
$this->template->javascriptcustom = '';
$this->template->login = $login;
}
public function after() {
$this->response->body($this->template);
parent::after();
}
}
Или отдельно компоненты которые могут вызываться по Ajax запросу:
Код:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Chunks_Commenting extends Controller_Auth {
public function action_showcomments() {
$comments = Model::factory('Comments')->getcommentsandusers();
$id = 1;
$commenttpl = '';
if ($this->auth->logged_in()) {
$user = $this->user;
$username = $user->username;
}
foreach($comments as $comment) {
if($this->auth->logged_in()) {
if($comment->username == $username) {
$options = '<div class="option1"><a href="#">Цитировать</a></div> <div class="option2"><a href="#">Редактировать</a></div> <div class="option3"><a href="#">Удалить</a></div>';
}
else {
$options = '<div class="option1"><a href="#">Цитировать</a></div>';
}
}
else {
$options = '';
}
$data = array(
'id' => $id,
'title' => $comment->title,
'content' => $comment->comment,
'username' => $comment->username,
'datetime' => $comment->created,
'options' => $options
);
$id++;
$commenttpl .= View::factory('Public/Chunks/Comment', $data);
}
//View::factory('profiler/stats')
$this->response->body($commenttpl);
}
}
В общем проблема как была так и осталась... Когда контролер Логин в главном шаблоне видит одного пользователя, система комментариев видит другого. Но везде для работы с авторизацией используются: $this->auth и $this->user
Которые берут данные из самого главного коммона Auth.
Это проблема сессий какая-то... Но я не знаю как её решить...