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)
How to access and execute specific php file in OctoberCMS when creating a backend plug-in?
1.3k views Asked by David Lundquist At
2
There are 2 answers
0
On
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.
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:
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:
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.