joomla找不到我的模特

时间:2011-06-21 18:13:34

标签: php joomla joomla1.5

由于某种原因我不能在任何地方加载我的模型。不在我的控制器中,不在我看来。这是我的代码

<?php
/**
* Joomla! 1.5 component ad_maker
*
* @version $Id: view.html.php 2011-06-16 12:55:02 svn $
* @author
* @package Joomla
* @subpackage ad_maker
* @license GNU/GPL
*
* makes ads
*
* This component file was created using the Joomla Component Creator by Not Web Design
* http://www.notwebdesign.com/joomla_component_creator/
*
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class Ad_makerViewDefault extends JView {
    function display($tpl = null) {

      $model =& $this->getModel('Ad_maker');
      $model->get('AdList');

        parent::display($tpl);
    }
}
?>

我的模特位于

com_ad_maker /模型/ ad_maker.php

<?php
/**
* Joomla! 1.5 component ad_maker
*
* @version $Id: ad_maker.php 2011-06-16 12:55:02 svn $
* @author
* @package Joomla
* @subpackage ad_maker
* @license GNU/GPL
*
* makes ads
*
* This component file was created using the Joomla Component Creator by Not Web Design
* http://www.notwebdesign.com/joomla_component_creator/
*
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');
jimport('joomla.application.component.controller' );
jimport('joomla.database.table');

class Ad_makerModelAd_maker extends JModel {

    function __construct() {
      parent::__construct();
    }

   public function getTest()
   {
      echo "this is a test";   
   }

   public function store()
   {
      $post = $this->_state->get('request');

      $db =& JFactory::getDBO();

      $url = "images/ads/" . $_FILES["file"]["name"];
      $durl =  $_SERVER['DOCUMENT_ROOT']."/images/ads/" . $_FILES["file"]["name"];   
      move_uploaded_file($_FILES["file"]["tmp_name"],$durl);

      $query = "INSERT INTO #__ad_maker (ad_name, image_url, tags) VALUES ('$post[ad_name]', '$url', '$post[tags]')";       
      $db->setQuery($query);
      $result = $db->query();
   }

   public function getAdList()
   {
      $query = "SELECT * FROM #__ad_maker";
      $db->setQuery($query);
      $result = $db->query();

      return $result;   
   }

   public function deleteAd($id)
   {
      $query = "DELETE * FROM #__ad_maker WHERE id = $id";
      $db->setQuery($query);
      $result = $db->query();      
   }
}
?>

我收到以下错误

Fatal error: Call to a member function get() on a non-object in /home/website/public_html/administrator/components/com_ad_maker/views/default/view.html.php on line 26

这是我的控制器

com_ad_maker / Controller.php这样

<?php
/**
* Joomla! 1.5 component ad_maker
*
* @version $Id: controller.php 2011-06-16 12:55:02 svn $
* @author
* @package Joomla
* @subpackage ad_maker
* @license GNU/GPL
*
* makes ads
*
* This component file was created using the Joomla Component Creator by Not Web Design
* http://www.notwebdesign.com/joomla_component_creator/
*
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );
require_once( JPATH_COMPONENT.DS.'helpers'.DS.'helper.php' );

/**
* ad_maker Controller
*
* @package Joomla
* @subpackage ad_maker
*/
class Ad_makerController extends JController {
    /**
     * Constructor
     * @access private
     * @subpackage ad_maker
     */
    function __construct() {
        //Get View
        if(JRequest::getCmd('view') == '') {
            JRequest::setVar('view', 'default');

         JRequest::setVar('view', 'default');
        }

        $this->item_type = 'Default';
        parent::__construct();
    }

   function add()
   {
      $post   = JRequest::get('post');
      $model =& $this->getModel('Ad_maker');

      $model->setState('request', $post);      
      $model->store();      
   }
}
?>

1 个答案:

答案 0 :(得分:6)

您的视图名称为default,因此Joomla将尝试从组件的default目录中加载名为models的模型。将com_ad_maker/models/ad_maker.php更改为com_ad_maker/models/default.php并将class Ad_makerModelAd_maker extends JModel更改为class Ad_makerModelDefault extends JModel,它应该有效。