I'm experimenting with creating my own Joomla component. The component searches records in database tables, but I have a problem with how to show them.
I have a search form that sends the search phrase to the controller.php
.
<form action="<?php echo JRoute::_('index.php'); ?>" method="post" class="form-inline">
<input name="company" id="form_hladat" maxlength="150" class="inputbox search-query input-medium" type="search" placeholder="hladat" />
<input type="hidden" name="task" value="search" />
<input type="hidden" name="option" value="com_regne" />
</form>
In the controller.php
I have a search function. The function performs a search and redirects me to view basic
.
public function search() {
// Slashes cause errors, <> get stripped anyway later on. # causes problems.
$badchars = array('#', '>', '<', '\\');
$searchword = trim(str_replace($badchars, '', $this->input->getString('company', null, 'post')));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('cin','tin','vatin','name','formatted_address','street','reg_number','building_number','postal_code','municipality','country','established_on','terminated_on','vatin_paragraph','registration_office','registration_number','formatted_street','street_number','rpo_organizations_id')))
->from($db->quoteName('corporate_bodies'))
->where($db->quoteName('cin') . ' LIKE '. $db->quote($searchword) . ' OR ' . $db->quoteName('name') . ' LIKE ' . $db->quote('%'.$searchword.'%'));
$db->setQuery($query);
$rows = $db->loadObjectList();
$results = $rows;
foreach ($results as $result):
$name = $result->name;
$cin = $result->cin;
$rpo_id = $result->rpo_organizations_id;
$company_demise = $result->terminated_on;
endforeach;
$view = $this->getView('basic','html');
$view->results = $results;
$view->display();
//$this->setRedirect(JRoute::_('index.php?option=com_regne&view=basic', false));
}
And that's where my problem starts. I do not know how to get search results (array).