Joomla 3: How do I use the raw format without adding format=raw to the URL?

笑着哭i 提交于 2019-12-25 12:43:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!