I would like to be able to serve a php file that is not encumbered by the OctoberCMS backend theme for use in a new window. (A standalone page)
2 Answers
How to use a custom "roll your own PHP page" in the creation of an OctoberCMS backend plug-in
Turns out the answer is super simple:
- in your plugin directory plugins/acme/cheesyplugin/ add a view folder.
- Save your PHP file in the view directory example myphppage.php .
- Create a controller or use the existing one of your choice.
Create a method (for example lets call my method myphppage) in the contoller.
Add the following code to your method on the controller, for example:
//method inside your chosen controller class public function myphppage(){ return \Response::view( 'acme.cheesyplugin::myphppage', ['a'=>$this])->header('Content-Type', "text/html"); }
All done
You now have a "roll your own PHP page that will render as you please, but still has all the advantages of being part your backend session.
To navigate to the your php page you would go like this: PHP example: http://[server]/backend/[you_as_publisher]/[plugin_name]/[controller_name]/[your_custom_method]
Note that second attribute for Response::view() is an array of Variables your custom page can access. you can change the content type at whim. Ideal for binaries like PDF's etc.

- 690
- 7
- 19
-
Can we also apply the layout to this php file? – MSN Feb 27 '19 at 01:53
There are two ways of doing this.
The first one is to make a file called routes.php
in any of your plugins directory and put some code like the following:
Route::get('/welcome', function(){
?>
//Here goes my HTML,CSS,JS,PHP CODE !
<?php
});
Another way also in routes.php
is to redirect your route to a view like the following code:
Route::get('/welcome', function(){
return view('mynamespace.mypluginname::welcome');
});
And the view should be within the plugin you provided its namespace and its name in the previous code. And it should be within a folder called views
so its full path should be plugins/mynamespace/mypluginname/views/welcome.blade.php
And as you can see in this way you can use Blade
template engine.
I hope this helps.

- 1,000
- 2
- 8
- 23