No, its modules views. I'm writing CMS on FUEL and I need in every module widget.php view for auto render widgets;)Charlie Black wrote on 02/05/11 6:47 pm:Have you tried to put your view in APP/views/ directory?
Ben Corlett wrote on 02/07/11 10:22 am:As long as you put the namespace of the module at the top of the view, you can call views HMVC-like. I'm 99% sure that's how you do it. I'm on my iPhone just now, when I'm on my laptop I'll check and paste the code (I've achieved this several times in a project management app I'm building on fuel)
class Base extends Controller_Template {
public function before()
{
parent::before();
//Initalize session
//$session = Session::instance();
Asset::css(array('main.css'), array(), 'css', false);
Asset::js(array('jquery.min.js'), array(), 'js', false);
$this->template->login_error = null;
if (\Auth::check())
{
$user = Auth::instance()->get_user_id();
$this->user_id = $user[1];
$this->template->logged_in = true;
}
else
{
$this->template->logged_in = false;
}
//Widgets init
\Fuel::add_module('ideology', true);
\Fuel::add_module('publications', true);
}
public function action_404()
{
// Set a HTTP 404 output header
Output::$status = 404;
$this->template->title = '404. Page not found.';
$this->template->content = View::factory('welcome/404');
}
}
... <div id="sidebar"> <?php echo @\Ideology\Controller_Ideology::widget(); ?> <?php echo @\Publications\Controller_Publications::widget(); ?> </div> ...
namespace Publications;
class Controller_Publications extends \Base {
public function before()
{
parent::before();
}
public function action_index()
{
$this->template->title = 'Publications';
$this->template->content = \View::factory('publications_index');
}
public static function widget()
{
$data = array();
return \View::factory('widget', $data);
}
}
// Views/template.php
<?php echo Request::factory('publications/widget')->execute()->output() ?>
// Then in publications/classes/controllers/publications.php
public function action_widget()
{
$data = array();
$this->response = $view->factory('widget', $data);
}
// I believe the stuffup is caused by something in the after() function of the controller
// and that's why it's getting the wrong view. especially because your'e putting a static
// function in a controller, which means it's not really part of that object but more a
// virtual 'self'.
//
// try maybe making a file under publications/classes called publications (not under controllers).
// have the static function there, which returns the HMVC call (the Request::factory()->execute()->output();
class Foo extends \Controller_Template
class Controller_Template extends Fuel\Core\Controller_Template
{
public function before()
{
// blah
}
}
/** * Set Template * * Override a template after it is defined * (used for loading different templates * for different user agents) * * @param string name of the template * @return Controller_Template */ protected function _set_template($template, $refresh = false) { $this->template = \View::factory($template); return $this; }
):
// classes/controllers/somecontroller.php
public function action_test()
{
if ($foo == $bar)
{
$this->_set_template('sometemplate/default');
}
}
...
public function set_filename($file)
{
if (($path = [b]\Fuel::find_file('views', $file))[/b] === false)
{
throw new \View_Exception('The requested view could not be found: '.\Fuel::clean_path($file));
}
// Store the file path locally
$this->_file = $path;
return $this;
}
...
...
public static function find_file($directory, $file, $ext = '.php', $multiple = false)
{
$path = $directory.DS.strtolower($file).$ext;
[b]if (static::$path_cache !== null && array_key_exists($path, static::$path_cache))
{
return static::$path_cache[$path];
}[/b]
$paths = static::$_paths;
// get the paths of the active request, and search them first
if ($active = \Request::active())
{
$paths = array_merge($active->paths, $paths);
}
$found = $multiple ? array() : false;
foreach ($paths as $dir)
{
$file_path = $dir.$path;
if (is_file($file_path))
{
if ( ! $multiple)
{
$found = $file_path;
break;
}
$found[] = $file_path;
}
}
[b]static::$path_cache[$path] = $found;[/b]
static::$paths_changed = true;
return $found;
}
...
It looks like you're new here. If you want to get involved, click one of these buttons!