The Stack Overflow podcast is back! Listen to an interview with our new CEO.
9

Actually JLoader::register('TestHelper','/path/to/test.php'); dosen't load file, it just registers it to be able to autoload file if class is instantiated. Do require it instantly, you want to use: JLoader::import('TestHelper','/path/to/test.php'); Note: for this your file name should be TestHelper.php. which will include_once the file if it exists (...


4

Take a look at JControllerAdmin what is used to extend your controller. In __construct function on line 62 unpublish is set to use publish function. So there is no function like unpublish. And in publish function you can get task name with $task = $this->getTask();. Possible values are publish, unpublish, archive, trash and report. So you can compare, ...


3

You can't set a class property to a dynamic value, such as a method call, during declaration like you're attempting. See http://php.net/manual/en/language.oop5.properties.php You would need to set it in your constructor. JLoader::Register('MyComHelperConfig', JPATH_COMPONENT_ADMINISTRATOR . '/helpers/config.php'); class MyComController extends ...


3

You are calling parent::publish(). This method has an array which maps tasks to states (line 190): $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); Then it gets the task (next line): $task = $this->getTask(); Which is "setup" in your case. After that it tries to read the value of the task ...


3

I think your view files are missing or view class is named incorrectly (correct is [Prefix]View[Viewname]). If I change the name of administrator/components/com_banners/views/ to /viewx/ I get the following error: An error has occurred. 500 View not found [name, type, prefix]: banners, html, bannersView Switch it back to /views/ - and error goes away.


3

jimport('joomla.application.component.controller'); JLoader::import('controllername', JPATH_ROOT . '/components/com_componentname/controllers'); $controller = JControllerLegacy::getInstance('controllername'); $controller->execute('task'); Not sure what you want to do, which task you want to execute, etc. But that should work as a start.


3

Overwrite a controller is something that I don´t dare to do, even it is possible. I recommend you try to use another approach Option 1 – Modifying the controller to add an event trigger and ask the developer to include it in the next version. As explained here: https://techjoomla.com/joomla-development/adding-plugin-triggers-in-your-extensions-how-a-why....


2

It is a complex solution. This plugin should help: Plugin to override 3rd Component controllers, models and views and Modules. Also you can read about overrides in Joomla docs: How to override the component mvc from the Joomla! core


2

You can use .htaccess In joomla with apache rewrite feature. Rename the file htaccess.txt to .htaccess In root joomla folder; Enable Apache rewrite In global configuration In joomla admin area.


2

This can be done by using ->insert() and ->values(), with the $values being an array of the strings with the columns to insert. $db = JFactory::getDbo(); $query = $db->getQuery(true); $columns = array('col_one','col_two'); $values = array(); // Proper escaping/quotes should be done here, and probably in a loop foreach ($arr as $key => $value) { $...


2

Use the following: $menu =& JSite::getMenu(); $activeMenu = $menu->getActive(); $Itemid = $activeMenu->id; or $menu =& JSite::getMenu(); $activeMenu = $menu->getActive(); $Itemid = $activeMenu->query['Itemid']; To get your message being passed you need to retrieve it from the application input $...


2

After some testing, I was able to replicate the issue: **A form redirects to a view without a menu item or redirects to itself relatively to a url like this one: component/mycomponent/myview (It doesn't matter if the view has a menu item or not, this is just stupid Joomla routing.)** Therefore the following has to be done to prevent the error: 1) the ...


2

OK, comments are not the easiest place to talk in details (too short, too easy to misinterpret) so I'll post this here. It may be a bit wide-ranging and high-concept at first b/c of the lack of detail I'm starting out with, but bear with me and we can edit out the parts that don't fit the more concrete scenario, as it gets defined, and flesh out the parts ...


1

I never figured out how to use $this, but it was pretty straightforward otherwise. This checks to see if the add method exists in the Article controller. $ToolsClass = 'ContentControllerArticle'; $methodToFind = 'add'; JLoader::register($ToolsClass, JPATH_SITE . '/components/com_content/controllers/article.php'); if (!method_exists($ToolsClass, $...


1

Use your controller only for redirection purpose. For database stuff use your view model. Make sure your view name, controller file name, model file name are same. Form: <form method="post" class="form-inline"> <input name="company" id="form_hladat" maxlength="150" class="inputbox search-query input-medium" type="search" placeholder="hladat" /&...


1

"file" is the frontend controller called here. /components/com_your_component/controllers/file.php class Your_ComponentControllerFile extends JControllerLegacy { public function submit(){ // do something } } You can load admin controllers and helpers within this controller. Please consider this too: https://docs.joomla.org/...


1

No, there isn't a way to pass arguments into methods. Specifically, this has to do with how JControllerLegacy::execute() routes the request. So you're left with using the request or session to fetch your needed data.


1

I think you need to path 'template_path' in the config as well. Probably something like $config['template_path'] = array( JPATH_COMPONENT.'/views/tmpl', $custom_view_path.'/tmpl', /* maybe other override place here like the template */ ); I don't think any of the autogenerated paths match your file structure (lines 2703 to 2725). if (!...


1

It appears you are submitting the from without executing the validation. Using jQuery, you could listen for the form submit event, check validation and submit the form if it passes. At the top of your PHP file add the following to load the jQuery library: JHtml::_('jquery.framework'); Add the below JS to the page inside a script tag: (function($) { ...


1

Here is a CLI script I made that allows you to call controllers just as you would via http. Just add it to the cli folder named something like kewlcomponent.php. <?php /** * This is a CRON script which should be called from the command-line, * not the web. For example something like: * env php /path/to/joomla/cli/app.php */ // Make sure we're being ...


1

The simplest way to implement a Confirmation dialog is on the client side, with Javascript routine. You can check how JToolbar does it: $bar = JToolbar::getInstance('toolbar'); // Add a trash button. $bar->appendButton('Confirm', JText::_('COM_XXX_CONFIRM_PURGE'), 'trash', $alt, $task, $check, false); In Javascript terms: if (confirm('....


1

To get Menu Params This one is perfect I was searching few hrs and this solve my issue of Joomla 3.6.5 & PHP 7.1 0: Using $this when not in object context Solution: $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $itemId = $active->id; $menuparams = $menu->getParams($itemId);


1

An Table with 100 cols, should not be handled by hand.In most cases is something forgotten. On Changes you have heavy task to find in code the Positions Basically us the JForm with the correct Data-Definition (validation) and an JTable object that is connected with the table .. it prevents from a lot of errors ;-) <?php /** Example peace to get the ...


1

It's probably because of textarea name, don't use 'task' which is in use for controller routing requests, try "mytask" or whatever, and update references elsewhere in the code


1

Recently i made a component when i change the o publish status via Ajax request. I made a method setPublish($id, $status) on model, and two methods on my controller: public function setPublishTrue(){ $data = JRequest::get('post'); //get the item id via post $model = $this->getModel('Promocaos'); $model->setPublish($data['id'], 1); } The ...


1

Yes, it is possible, but your have to create your own CLI script to translate the command line to the Joomla API command. For example: To receive a list of IDs (comma separated) from an argument Initialize JInput, and send it to your controller. You can check any of the cli/ script to create your own script.


1

For anyone that might end up here through a Google search, trying to find a solution to a similar problem: Usually fatal errors especially after an update may mean that some files didn't copied over correctly. Reinstalling Joomla and extensions and update to latest version usually solves such issues. In many cases I would recommend to perform a manual re-...


1

Let you know Goto backend -> Menus -> Add new menu item -> Here you can create the one menuitem with title and alias that alias name display in url. (or) Try like this Goto backend -> System -> Global configuration -> Turn on the sef url.


Only top voted, non community-wiki answers of a minimum length are eligible