I have created a system plugin in joomla and created a custom method that is mymethod(). Now i want to call this method via ajax. I have tried link but it will create new ajax plugin but i want to call system plugin custom method not create new plugin.
You can use the plugin system event onAfterInitialise().
Use this url for ajax: index.php?type=mymethod
This leads to:
function onAfterInitialise() {
$jinput = JFactory::getApplication()->input;
if($jinput->get('type')=='mymethod') {
// your code here
}
}
The link is ok. You just need to change the folder name from ajax to system. Prior to joomla 3.4 it was mandatory to place your plugin in ajax folder but now you can place in any folder. Your code will look like this
JPluginHelper::importPlugin('system');
$plugin = ucfirst($input->get('plugin'));
$dispatcher = JEventDispatcher::getInstance();
try
{
$results = $dispatcher->trigger('myMethod' . $plugin);
}
catch (Exception $e)
{
$results = $e;
}
Follow rest instruction as given there.
Related
I am building a laravel web application which involves the usage of Moodle Service (version 3.6). I have done autologin with a plugin.
The problem is that clicking the Take Course button on my external application will autologin to Moodle (via the plugin), but does not redirect the user to the course described in the button.
Is there a mechanism to do this?
The plugin you are using already has an option to do this:
See the user_login_userkey() method here
/**
* Logs a user in using userkey and redirects after.
*
*/
public function user_login_userkey() {
$keyvalue = required_param('key', PARAM_ALPHANUM);
$wantsurl = optional_param('wantsurl', '', PARAM_URL);
if (!empty($wantsurl)) {
$redirecturl = $wantsurl;
} else {
$redirecturl = $CFG->wwwroot;
}
if (isloggedin()) {
$this->redirect($redirecturl);
}
So you only need to pass the wantsurl parameter having the course URL and it should automatically redirect you to the course after login.
From the plugin github page you linked, I noticed the section:
if (isset($courseid)) {
$path = '&wantsurl=' . urlencode("$domainname/course/view.php?id=$courseid");
}
if (isset($modname) && isset($activityid)) {
$path = '&wantsurl=' . urlencode("$domainname/mod/$modname/view.php?id=$activityid");
}
I believe you can define a redirect url after the login by adding the wantsurl query parameter to your login url.
I'm wondering how I can render a view, or display a page with my default theme in OctoberCMS, via a route that executes a function in a controller.
If I have the following route:
Route::get('bransje', [
'uses' => 'Ekstremedia\Cityportal\CPController#bransje'
]);
And in my controller CPController ive tried several things, like I used to with Laravel:
public function bransje() {
$stuff = Stuff::with('info');
return View::make('cms::bransje')->with('stuff',$stuff);
}
But I cannot seem to get it to work, and I've tried to search the web, but it's hard to find answers. I have found a workaround, and that is to make a plugin component, then I can include that component and do:
public function onRun()
{
$this->eventen = $this->page['stuff'] = $this->stuff();
}
protected function stuff()
{
return ...
}
Is there any way so I can make pages without using the Cms, and that are wrapped in my default theme? I've tried
return View::make('my-theme-name::page');
and a lot of variants but no luck.
I know I can also do a:
==
public function onRun()
{
}
in the start of my page in the cms, but I'm not sure how to call a function from my plugin controller via there.
You can bypass frontend routing by using routes.php file in your plugin.
Full example in this video turotial.
If this answer can still be useful (Worked for October v434).
I have almost the same scenerio.
What I want to achieve is a type of routing like facebook page and profile.
facebook.com/myprofile is the same url structure as facebook.com/mypage
First I create a page in the CMS for each scenario (say catchpage.htm)
Then a created a catchall route at the buttom of routes.php in my plugin that will also not disturb the internal working of octobercms.
if (!Request::is('combine/*') && !Request::is('backend/*') && !Request::is('backend')) {
// Last fail over for looking up slug from the database
Route::get('{slug}/{slug2?}', function ($slug, $slug2 = null) {
//Pretend this are our routes and we can check them against the database
$routes = ["bola", "sade", "bisi", "ade", "tayo"];
if(in_array($slug, $routes)) {
$cmsController = new Cms\Classes\Controller;
return $cmsController->render("/catchpage", ['slug' => $slug]);
}
// Some fallback to 404
return Response::make(View::make('cms::404'), 404);
});
}
The if Request::is check is a list of all the resource that october uses under the hood, please dont remove the combine as it is the combiner route. Remove it and the style and script will not render. Also the backend is the url to the backend, make sure to supply the backend and the backend/*.
Finally don't forget to return Response::make(View::make('cms::404'), 404); if the resource is useless.
You may put all these in a controller though.
If anyone has a better workaround, please let us know.
I want to lazy load several PartialTemplates in an Extbase Controller via Ajax.
Therefore I found the following script to render only a Partials but it doesn't work in my context:
private function renderPartial($partialName='', $data = array()){
if($partialName==''){
throw new \TYPO3\CMS\Extbase\Mvc\Exception\RequiredArgumentMissingException('The Partial name must be defined.', 123456789);
}
$this->templateView = $this->objectManager->create('TYPO3\CMS\Fluid\View\TemplateView');
$res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
$this->templateView->setLayoutRootPath($res);
$this->templateView->setPartialRootPath($res . 'Partials/');
$this->templateView->setRenderingContext($this->objectManager->create('TYPO3\CMS\Fluid\Core\Rendering\RenderingContext'));
$this->templateView->setControllerContext($this->controllerContext);
return $this->templateView->renderPartial($partialName, Null, $data);
}
This results in the following Error:
Fatal error: __clone method called on non-object in /var/www/html/typo3_src-7.6.0/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php on line 281
I Goolge for this and found many posts having the same problem. What can I do to make this working. A workaround using the StandaloneView and setTemplatePathAndFilename() works well. Is it possible to use Partial without a Layout/Section?
EDIT:
I added some debug Informations and the Controller Action...
public function searchAction(\PCON\Avm\Domain\Model\DemandSearch $demandSearch = NULL) {
//GlobalSearch
if($demandSearch != NULL) {
$searchResult = $this->demandSearchRepository->findDemanded($demandSearch);
$this->view->assign('searchResult', $searchResult);
}
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->controllerContext);
$this->templateView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\TemplateView');
$res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
$this->templateView->setLayoutRootPath($res);
$this->templateView->setPartialRootPath($res . 'Partials/');
$this->templateView->setRenderingContext($this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'));
$this->templateView->setControllerContext($this->controllerContext);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->templateView);
return $this->templateView->renderPartial('Search/SearchForm.html', Null, array('searchResult'=>$searchResult));
}
I do not think that this is a AJAX Problem (definded by PageNum).
If I call the controller Action without AJAX the same error appears ...
You can't use renderPartial() oder renderSection() from extbase/php in StandaloneView. It's a missing feature that will probably not be implemented in TYPO3 7.6 and below. See this task: https://forge.typo3.org/issues/54509
However, you can use partials and sections in Fluid. Just assign your variables, then render your template with
$this->templateView->render();
And use partials and section in your Fluid template.
I am trying to auto create jomsocial albums using a plugin after adding the jomsocial library in plugin in the event function onUserLogin. onUserLogin if i am trying to fetch the $my = JFactory::getUser(); is returs null value. SO the jomsocial library also act same with user values.
Can't be sure without any of you code to look at, but the Joomla user plugin uses this when it starts:
public function onUserLogin($user, $options = array())
{
$instance = $this->_getUser($user, $options);
As many of you know the controller in Joomla 2.5 changed from
// Create the controller
$classname = 'mycomponentController'.$controller;
$controller = new $classname( );
// Perform the Request task
$controller->execute( JRequest::getVar('task'));
// Redirect if set by the controller
$controller->redirect();
to something along the lines of
// Get an instance of the controller prefixed by the component
$controller = JController::getInstance('mycomponent');
// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
// Redirect if set by the controller
$controller->redirect();
Now in Joomla 1.5 as well as by using the table you could run a task by running the link
index.php?option=com_mycomponent&controller=specificcontroller&task=randomtask
However this style of link doesn't work with the new controller - does anyone know how to format this link in Joomla 2.5 if you're using the new controller?
You can combine task and controller so that it'll call the task of the specified controller.These will be .(dot) seperated. try this-
index.php?index.php?option=com_mycomponent&view=viewname&task=specificcontroller.randomtask
Read More - http://docs.joomla.org/JController_and_its_subclass_usage_overview