简体   繁体   中英

joomla component not calling any model function and controller function

I am sending a ajax request in function and calling model function but model function not calling and i also try a local controller function but not call any local function

controller

<?php
    defined('_JEXEC') or die;
    jimport('joomla.application.component.controller');

    class IgalleryController extends JControllerLegacy
    {
        function __construct($config = array())
        {   
            $config['base_path'] = JPATH_SITE.'/components/com_igallery';
            parent::__construct($config);
        }

        function ajaxrequest()
        {
            //JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_igallery/models', 'category');

            //echo $db = JFactory::getDBO();
            $model             = $this->getModel('category');
            $this->params      = JComponentHelper::getParams('com_igallery');
            $this->source      = JRequest::getCmd('igsource', 'component');
            //
            $igid              = JFactory::getApplication()->input->get('igid');
            $Itemid            = JFactory::getApplication()->input->get('Itemid');
            $this->catid       = JRequest::getInt('igid', 0);
            $this->category    = $model->getCategory($this->catid);
            $profileId         = JRequest::getInt('igpid', 0);
            $profileId         = $profileId == 0 ? $this->category->profile : $profileId;
            $user              = JFactory::getUser();
            //print_r($user); die;
            $this->profile     = $model->getProfile($profileId);

            $searchChildren    = JRequest::getInt('igchild', 0);
            $tags              = JRequest::getVar('igtags', '');
            //
            $limit             = JRequest::getInt('iglimit', 0);
            $limit             = $limit == 0 ? 1000 : $limit;
            $foo               = $this->foo();
            print_r($foo);
            $this->photoList = $model->getCategoryImagesList($this->profile, $this->catid, $tags,    $searchChildren, $limit);
            //
            print_r($this->photoList);
        }

        function $this->foo()    
        {
            return true; 
        }   
    ...

in above code also print $foo variable but not get true or 1 value;

You must override function getModel() in your controller parent model has construct:

public function getModel($name = '', $prefix = '', $config = array('ignore_request' => true))

You lacked $prefix and you also add include path of the model file if necessary

Regarding issue return value true of false, you must echo 1 for true of 0 for false and stop the process by die function. The return method will show so much html of joomla page.

function $this->foo()    
    {
       echo 1;
       die;
    }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM