Reboot
Reboot

I know we can include a routes.php file with our plugin to define routes using the closure style:

Route::get('/', function() { return 'Hello World'; });

But can you define routes that use the controller action style within the routes.php file? ex:

Route::get('/staff', 'staff@viewAll');

Last updated

Reboot
Reboot

Never mind, I see that you can use methods of a controller's class. For anyone else looking for this the documentaiton is here: http://octobercms.com/docs/backend/controllers-views-ajax#actions-views-routing

Last updated

deroccha
deroccha

can you please post your solution I do not find a way to get forward with this ajax issue

that0n3guy
that0n3guy

I've done this like so:

Route::get('webforms/submit/{secret}', array('as' => 'webform.api.get', 'uses' => 'OCA\Webforms\Classes\Ocaforms@store'));
Route::post('webforms/submit/{secret}', array('as' => 'webform.api.post', 'uses' => 'OCA\Webforms\Classes\Ocaforms@store'));

Route::get('backend/that0n3guy/api/formposts/{id}', array('as'=>'that0n3guy.api.formposts', 'uses'=>'OCA\Webforms\Classes\Ocaforms@getDatatable'));

My namespace for my class is OCA\Webforms\Classes\Ocaforms. The third one is used by datatable (http://www.datatables.net/) for ajax loading a specific table from mongodb.

deroccha
deroccha

Thanks looks promissing I will give a try.

deroccha
deroccha

Jus a short question. Would be not possible to use the Backends DataTable which is used for the Lists in Plugins Frontend?

deroccha
deroccha

so

backend/that0n3guy/api/formposts
is your plugins controller ? how you include OCA\Webforms\Classes\Ocaforms@getDatatable ?
that0n3guy
that0n3guy

Jus a short question. Would be not possible to use the Backends DataTable which is used for the Lists in Plugins Frontend?

I don't how to use backends lists for frontend... might be possible, but I don't know.

backend/that0n3guy/api/formposts is your plugins controller ? how you include OCA\Webforms\Classes\Ocaforms@getDatatable ?

No plugins\oca\webforms\classes\Ocaforms.php is my class file. OCA\Webforms\Classes\Ocaforms is the namespace. That 'as'=>'that0n3guy.api.formposts', you see is just giving the route a name, see: http://laravel.com/docs/4.2/routing#named-routes.

deroccha
deroccha

great seems to work.

manrox.drag17392
manrox.drag17392

you can do it use / Functions to allow RESTful actions /

public static function getAfterFilters() {return [];}

public static function getBeforeFilters() {return [];}
public static function getMiddleware() {return [];}
public function callAction($method, $parameters=false) {
  $action = 'api' . ucfirst($method);
  if (method_exists($this, $action) && is_callable(array($this, $action)))
  {
    return call_user_func_array(array($this, $action), $parameters);
  } else {
    return response()->json([
        'message' => 'Not Found',
    ], 404);
  }
}

add the above your controller and you can make rest calls from your controller and define your route apifunctions inside this controller like # public function apicreate(){ some code here }

Last updated

andre_yang
andre_yang

Assuming we have Controller named 'Custom' and you want to create a route to its index() function.
---Try this code in your route.php
Route::any('test', 'Author\PluginName\Classes\Custom@index')
or
Route::get('test', 'Author\PluginName\Classes\Custom@index')
--------------------------------------------------------------------------------------------------------------------

in Author\PluginName\Classes\Custom.php -> do this

<?php namespace Author\PluginName\Controllers;

use Cms\Classes\Controller;

class Custom extends Controller
{

public function index(){

return "Routed to index";

}



}

Last updated

1-11 of 11