dqdtgiw4736 2011-06-21 18:13
浏览 49
已采纳

joomla找不到我的模特

for some reason I can not load my model anywhere. not in my controller, not in my view. here is my code

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

My model is located at

com_ad_maker/models/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();      
   }
}
?>

I get the following error

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

here is my controller

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条回答 默认 最新

  • duanchao9559 2011-06-21 20:20
    关注

    The name of your view is default, so Joomla will attempt to load the model named default from your component's models directory. Change com_ad_maker/models/ad_maker.php to com_ad_maker/models/default.php and change class Ad_makerModelAd_maker extends JModel to class Ad_makerModelDefault extends JModel and it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解