2011-06-21 3 views
1

何らかの理由で私のモデルをどこにもロードできません。私の考えではなく、私のコントローラーではありません。ここに私のコードはjoomlaが私のモデルを見つけられません

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

である私のモデルは、私は次のエラー

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 /モデル/ 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();  
    } 
} 
?> 

に位置しています

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

答えて

6

Joomlaのは、あなたのコンポーネントのmodelsディレクトリからdefaultという名前のモデルをロードしようとしますので、あなたのビューの名前は、defaultです。 com_ad_maker/models/ad_maker.phpcom_ad_maker/models/default.phpに変更し、class Ad_makerModelAd_maker extends JModelclass Ad_makerModelDefault extends JModelに変更すると正常に動作します。

+0

add()関数では機能しますが、contstruct関数では機能しません。私のビューとモデルを特定の名前にする必要がある場合、なぜモデルの名前をgetModel( 'name')パラメータに入れなければならないのですか? – numerical25

+0

代わりにad_makerにビューを変更しましたが、まだ動作しています – numerical25

+0

view.html.phpファイルでは、 '$ this-> getModel( 'Ad_maker');'を使用する必要はありません。 view.html.phpでは、$ ad_list = $ this-> get( 'AdList'); '次に$ this-> assign( 'AdList'、$ ad_list);を実行してgetAdListからの結果を使用できます()をdefault.phpファイルに追加します。 – jlleblanc

関連する問題