I have a simple component that that will be performing CRUD for my mobile app on Joomla site.
These are the structure of my files
http://localhost/chichi-server/components/com_chichi/controller.php
http://localhost/chichi-server/components/com_chichi/chichi.php
http://localhost/chichi-server/components/com_chichi/controllers/getdata.php
http://localhost/chichi-server/components/com_chichi/controllers/postdata.php
in my chichi.php I have this
<?php
defined('_JEXEC') or die('access dedied');
jimport('joomla.application.component.controller');
$input = JFactory::getApplication()->input;
$controller=JControllerLegacy::getInstance('ChichiMobilePost');
$controller->execute($input->get('task'));
$controller->redirect();
And in controller.php I have
<?php
defined('_JEXEC') or die('access dedied');
jimport('joomla.application.component.controller');
class ChichiMobilePostController extends JControllerLegacy{
function diplay(){
echo 'Noting to do';
}
function create(){
echo 'Welcom to Create';
}
}
In my /controllers/getdata.php
<?php
defined('_JEXEC') or die('access dedied');
jimport('joomla.application.component.controller');
class ChichiMobilePostController extends JControllerLegacy{
//GET USER COLLECTIONS
function getcollection(){
//Prevent template from showing
$app =JFactory::getApplication();
$input = JFactory::getApplication()->input;
$userID = $input->post->get('userID');
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
try
{
$query
->select(array('*'))
->from($db->quoteName('#__user'))
->where($db->quoteName('id') .'=' . $userID .'');
$db->setQuery($query);
$results = $db->loadAssocList();
}
catch (Exception $e)
{
$this->setError('The error message you want');
return false;
}
echo json_encode(array('collect'=>$results));
$app->close();
}
};
My question how do I get query in /controllers/getdata/php to excute
I tried accessing it through
http://localhost/chichi-server/index.php?option=com_chichi&task=getdata.getcollection
But I get thi s error "(View not found [name, type, prefix]: get.getcollection, html, chichimobilepostView)"
However If I use
http://localhost/chichi-server/index.php?option=com_chichi&task=create
the controller.php is able to output "Welcome to create"
the reason why I am doing this is because there will be a lot post and get request from the mobile app and though I could each process in their own file.
I will be glad if anyone can help. me resolve this, Thank you very much