joomla组件不调用任何模型函数和控制器函数

时间:2016-02-26 10:05:55

标签: php joomla joomla-extensions

我在函数中发送ajax请求并调用模型函数但模型函数没有调用,我也尝试本地控制器函数但不调用任何本地函数

控制器

<?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; 
        }   
    ...

在上面的代码中也打印$ foo变量但不是true或1值;

1 个答案:

答案 0 :(得分:0)

您必须覆盖控制器中的函数getModel() 父模型有构造:

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

您缺少$前缀,并且如有必要,您还可以添加模型文件的包含路径

关于问题返回值true为false,必须回显1为0表示false,并通过die函数停止进程。返回方法将显示如此多的joomla页面的HTML。

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