1

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

3

Try to rename your class in /controllers/getdata.php to: ChichiMobilePostControllerGetdata Then Joomla can find the right class and execute getcollection() if you call it via

http://localhost/chichi-server/index.php?option=com_chichi&task=getdata.getcollection
  • Thanks, @Fruppel, I have done it, but it is still outputting 500 (View not found [name, type, prefix]: getdata.getcollection, html, chichimobilepostView) – David Addoteye Nov 5 '15 at 15:00
  • 1
    Did you spell the class name exactly like in my answer above? Uppercase "G" and "etdata" lowercase? – fruppel Nov 5 '15 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.