问题
I would like to load view.raw.php as a raw view just like if I has appended view=raw to the URL. But I would like to do it without adding view=raw to the URL.
I have tried the following inside my main controller and none work:
First I tried this:
JFactory::$document = null;
JFactory::getDocument();
Then I tried this:
$input = JFactory::getApplication()->input;
$input->set('format', 'raw');
And this:
$_REQUEST['format'] = 'raw';
And this: $urlparams['format']='raw'; $urlparams[]=array('format' => 'raw');
And this:
$doc = JFactory::getDocument();
$doc->setType('raw');
None of them seem to do the trick.
回答1:
To achieve this add the following inside the controller:
$document = JDocument::getInstance('raw'); //this new instance is a raw document object
$viewType = $document->getType();
// $viewname below is set in jinput or as you named it
$this->getView($viewName, $viewType);
$this->input->set('view', $viewName);
The above calls the view.raw.php
回答2:
I am not sure where you placed your code, but I if it is inside a template than the change is made too late and joomla already rendered in default format. Create a Plugin and use an event which is dispatched before rendering.
Here is a list of available events.
Good luck!
btw. I did something similar, using a plugin of type »system« and used the »onAfterInitialize« event.
来源:https://stackoverflow.com/questions/20905567/joomla-3-how-do-i-use-the-raw-format-without-adding-format-raw-to-the-url