How to access and execute specific php file in OctoberCMS when creating a backend plug-in?

1.3k views Asked by At

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

There are 2 answers

1
David Lundquist On

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:

  1. in your plugin directory plugins/acme/cheesyplugin/ add a view folder.
  2. Save your PHP file in the view directory example myphppage.php .
  3. Create a controller or use the existing one of your choice.
  4. Create a method (for example lets call my method myphppage) in the contoller.

  5. 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.

0
Ahmed Essam 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.