I am trying out to develop components from here. I am getting an error on the admin section
500 - An error has occurred.
Invalid controller: name='', format=''
How to debug this? I dont even know what code is relevant to post.
File: admin/controller.php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
class TestimonialsController extends JController {
function display($cachable = false) {
// set default view if not set
JRequest::setVar('view', JRequest::getCmd('view', 'Testimonials'));
// call parent behavior
parent::display($cachable);
}
}
File: admin/testimonials.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
$controller = JController::getInstance('Testimonials');
$controller->execute(JRequest::getCmd('task'));
$controller->redirect();
File: admin/views/testimonials/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
class TestimonialsViewTestimonials extends JView {
function display($tpl = null) {
$items = $this -> get("Items");
$pagination = $this -> get("Pagination");
//Check for errors
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this -> items = $items;
$this -> pagination = $pagination;
// Display the template
parent::display($tpl);
}
}
#mrN: What about the xml file? You can verify the sections <files> have all archives.
Example of error 500 when a file is missing:
<!-- file testimonials.xml -->
<!-- ERROR 500 because <em>admin/controller.php</em> is not installed -->
...
<administration>
<!-- Administration Menu Section -->
<menu>Testimonials</menu>
<!-- Administration Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /admin/ in the package -->
<files folder="admin">
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>testimonials.php</filename>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>
...
Related
Hey I am making my first module in Joomla!.
I want to create a new folder in Joomla!'s media manager when someone installs my module. I have been duck-duck-go-ing around and found some information. But I just can't get it to work. Probably because the information might be for older Joomla! versions. Or I might've implemented it wrong.
Anyway I came up with the following:
mod_mymodule.xml
<extension type="module" version="3.8.1" client="site" method="upgrade">
<files>
<scriptfile>install.componentname.php</scriptfile>
</files>
</extension>
install.createmap.php
<?php
$destination = JPATH_SITE."/images/mynewmap";
JFolder::create($destination);
?>
Can anyone explain me how to add a folder to the media manager (root/images) on installing a module in Joomla 3?
You need a script.php file which executes your install tasks:
https://docs.joomla.org/J3.x:Creating_a_simple_module/Adding_an_install-uninstall-update_script_file
Here is the example content the script.php:
<?php
// No direct access to this file
defined('_JEXEC') or die;
class mod_helloWorldInstallerScript
{
function install($parent)
{
echo '<p>The module has been installed</p>';
}
function uninstall($parent)
{
echo '<p>The module has been uninstalled</p>';
}
function update($parent)
{
echo '<p>The module has been updated to version' . $parent->get('manifest')->version . '</p>';
}
function preflight($type, $parent)
{
echo '<p>Anything here happens before the installation/update/uninstallation of the module</p>';
}
function postflight($type, $parent)
{
echo '<p>Anything here happens after the installation/update/uninstallation of the module</p>';
}
}
It contains a class with some methods so you can create the necessary folder structure. You want to extend the postflight method.
Which Joomla Platform / CMS class should I extend in order to make my own custom JDOC:include tags?
I would like to have custom JDOC tags like
<JDOC:include type="scripts" />
<JDOC:include type="scripts-body" />
and a bunch of other types.
You need to add new file at below location to add custom jdoc tag..
libraries/joomla/document/html/renderer/
File name should be same as the tag you are adding.. suppose you want to use scripts as tag then file name should be scripts.php
Now in this file you need to add below code. as tag name is scripts so class name should be JDocumentRendererScripts
<?php
defined('JPATH_PLATFORM') or die;
class JDocumentRendererScripts extends JDocumentRenderer
{
public function render($scripts, $params = array(), $content = null)
{
$contents = "";
//Do your work here
return $contents;
}
}
?>
Now you can use custom jdoc code <JDOC:include type="scripts" />
Hope this helps..
I am struggling to understand how to call sub controllers from a joomla component. What are to be placed in the controllers folder?
I have the entry point of my component like -
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// require helper file
JLoader::register('TieraerzteHelper', dirname(__FILE__) . DS . 'helpers' . DS . 'my_helper.php');
// import joomla controller library
jimport('joomla.application.component.controller');
$controller = JController::getInstance('MyController');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = $jinput->get('task', "", 'STR' );
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
Then if I want to call a controller, which is placed in the controllers folder, how do I do that?
You do a task=controller.function
As an example: You want to call the MycomponentControllerFoo in /controllers/foo.php and execute the function bar(). You use the following URL to call this:
index.php?option=com_mycomponent&task=foo.bar
Or you can use a form where there is a hidden task field.
I'm trying to create my first component for Joomla 2.5 but when try to execute get this error:
Error: 500
You may not be able to visit this page because of:
an out-of-date bookmark/favourite
a search engine that has an out-of-date listing for this site
a mistyped address
you have no access to this page
The requested resource was not found.
An error has occurred while processing your request.
View not found [name, type, prefix]: transportation, html, transportationView
What I've developed now is very basic and this is the controller under site/components/com_transportation/controllers/controller.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
class TransportationController extends JController {
}
And under site/components/com_transportation/views/view.html.php this:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
class TransportationViewTransportation extends JView {
// Overwriting JView display method
function display($tpl = null) {
// Assign data to the view
$this->msg = 'Hello World';
// Display the view
parent::display($tpl);
}
}
What I'm missing? What is wrong?
Your folder structure is incorrect. Your view file must be in site/components/com_transportation/views/transportation/view.html.php
Try this ,
When you start developing a new component go through the tutorial deeply,Then start modifying the samples .
follow this url it will help you .Its for 1.5 but the things are same for 2.5.
Only you have to mention version in the xml
<install type="component" version="1.5.0">
Also you will get a sample component download from this.
Download it and compare with your component then find the issue.
Hope this may helps..
View not found [name, type, prefix]: transportation, html, transportationView
Means just tha no view was found with the class name of transporationViewtransporation and the type view.html.php. What is the name of the class in your view.html.php file? is the second transportation really lower case like that? Also what are the name(s) of your layout and xml files in the tmpl folder?
I have view (frontend) in my own component (view.html.php):
class MevViewMev extends JView{
function display($tpl = null){
parent::display($tpl);
}
}
And template:
<?php defined('_JEXEC') or die('Restricted access'); ?>
<div>
ASFADSFDSF
</div>
How to display it without joomla template (head section, styles, etc). I want to call this part of jquery onclick method in the window.
To display the component only add "tmpl=component" parameter to url.
If need to display something besides component's view it can be customized - create "component.php" file in template's root folder and include in it whatever you need.
More templates can be done in the same way - create "some_template.php" in template's root folder and add "tmpl=some_template" parameter to url.
Start Edit
OK so the below works, but I found a better way. In your controller do ...
if (JRequest::getVar('format') != 'raw') {
$url = JURI::current() . '?' . $_SERVER['QUERY_STRING'] . '&format=raw';
header('Location: ' . $url);
// or, if you want Content-type of text/html just use ...
// redirect($url);
}
End Edit
You can set 'tmpl' to 'component', as suggested by Babur Usenakunov, in which case scripts and css may be loaded, like ...
JRequest::setVar('tmpl','component');
However if you want to create raw output you can add &format=raw or in your component make a view of type 'raw' ...
Unfortunately the only functional way I can find to make a viewType of raw render correctly is to call exit() after the view class calls parent::display() ...
In your controller.php ...
class com_whateverController() extends JController
{
function __construct()
{
// the following is not required if you call exit() in your view class (see below) ...
JRequest::setVar('format','raw');
JFactory::$document = null;
JFactory::getDocument();
// or
//JFactory::$document = JDocument::getInstance('raw');
parent::__construct();
}
function display()
{
$view = $this->getView('whatever', 'raw');
$view->display();
}
}
then in views/whatever/view.raw.php ...
class com_whateverViewWhatever extends JView
{
public function display($tpl = null)
{
parent::display();
exit; // <- if you dont have this then the output is captured in and output buffer and then lost in the rendering
}
}
I know this comes in very late, but for future readers, here's how I did it for my extension, without editing the template, or adding anything in the URL (since I have control over neither of those):
jimport('joomla.application.component.view');
use \Joomla\CMS\Factory;
// Comp stands for the Component's name and NoTmpl stands for the View's name.
class CompViewNoTmpl extends \Joomla\CMS\MVC\View\HtmlView {
// Force this view to be component-only
public function __construct() {
$app = Factory::getApplication();
$app->input->set('tmpl', 'component');
parent::__construct();
}