Search code examples
joomlajoomla-extensionscustom-component

joomla component custom view


I’m creating new component with component-creator.com for theater seat reservation. In my component I created one table for “theater halls” and one table for seat numbers with a foreign key to related hall. After installing , Let say I’ve created “theater A” with 20 seats and “theater B” with 35 seats.

The default view for seats or theaters in frontend is showing only a list.

Now what I want to show is each theater hall with their seat numbers in my custom layout like theater seat map and not as list.

What is the start point? Do I need to develop a module with dropdown to select each hall? If yes How to get seat numbers from database in my layout?

Thanks.


Solution

  • You can modify you thatre halls list view like this: Modify you theatre-halls model ( f.ex. com_yourcomponent/models/halls.php ) and add some stuff to the getItems() - method:

    public function getItems()
    {
        $items = parent::getItems();
        // new stuff:
        $db = JFactory::getDbo();
        foreach ($items as $key => &$value) {
            $db->setQuery("select * from #__theatres_seats where hall=" . $value->id);
            $value->seats=$db->loadObjectList();
        }
        // end new stuff
        return $items;
    }
    

    Replace the code with the correct table name and fk-name for your setup.

    Now you will have an object with all the seats for each theatre that you can use in the theatre list view. How you want to actually display the seats are up to you...