1
votes

I am building a joomla component called event, and I set a menu called event linked to this component. When I clicked on the menu link, it directed me not to the default event listing page, but the event registration page. I wonder what is wrong.

Here is the 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 EventController extends JControllerLegacy
{
    function display() { 
            $this->listing();
    }

    function listing() {


             JRequest::setVar( 'view', 'listing' );
             JRequest::setVar( 'layout', 'default' );
             parent::display(); 
    }

    function edit() {

             JRequest::setVar( 'view', 'edit' );
             JRequest::setVar( 'layout', 'default' );
             parent::display(); 

    }

    function save() {
            $model= & JModelLegacy::getInstance('Event','EventModel');
            $model->save_event();
    }

    function register() {

             JRequest::setVar( 'view', 'register' );
             JRequest::setVar( 'layout', 'default' );
             parent::display(); 

    }
    function register_save() {
            $model= & JModelLegacy::getInstance('Event','EventModel');
            $model->register_event();
    }



}//end 

The menu link is

http://www.example.com/Joomla_3.2.1/index.php?option=com_event&view=register&Itemid=481

instead of

http://www.example.com/Joomla_3.2.1/index.php?option=com_event

which is by default showing the listing page.

1
What is the url in the menu link (not the sef, the dynamic one that is stored). - Elin
You have to check link of your menu item as in above comment by @Elin - Jitendra Khatri
option=com_event&view=register&Itemid=481 That is a link to the register view ... so you'd expect it to go to the register page com_event/views/register/view.html.php. Do you have a folder called com_event/views/listing? - Elin

1 Answers

1
votes

You should create a manifest for the listing view; in Joomla! typically we map menu items to views. In the router.php you can optionally unset any parameters you don't need and don't want the url to show.

Tasks in the component's controller are typically used for in-component calls, and after execution should re-route to a view. The component router should be invoked on the views so that the nice SEF urls are shown for the views. Note: the router.php is only necessary if you are passing parameters to the view, as an example see com_content article view, which receives an id parameter. If you have no parameters, then you don't need to customize the router.php as Joomla will be generating the url including the view and layout.

To add the manifest to a view layout, for example /views/listing/tmpl/default.php, simply create an xml file default.xml. You need to create a manifest for any view layouts you intend to make available when the user creates a new menu item. Simply adding the XML manifest will make the new layout available in the menu item configuration.

In that file you can set extra request params with the <fieldset name="request"> wrapper around the fields.

The link is generated by Joomla, not by your component. You are only responsible for handling your part of the params, so option and Itemid will be handled by Joomla, any other params you should handle in the router.php (which is located in the root of your component, i.e. /components/com_listings/router.php )