joomla is not finding my model
for some reason I can not load my model anywhere. not in my controller, not in my view. here is my开发者_C百科 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();
}
}
?>
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.
精彩评论