Jump to content

my first module


spc

Recommended Posts

First error I spot:

		if (!Db::getInstance()->Execute('
			INSERT INTO `'._DB_PREFIX_.'searchbyvehicle`(`Regnr`, `Fordonstyp`)
			VALUES(abc123, Volvo 945 B230FT)')

 

should probably be:

		if (!Db::getInstance()->Execute('
			INSERT INTO `'._DB_PREFIX_.'searchbyvehicle`(`Regnr`, `Fordonstyp`)
			VALUES(\'abc123\', \'Volvo 945 B230FT\')')

 

or something like that: SQL string values must be quoted. It is a good idea to try your SQL syntax in phpMyAdmin or similar...

 

Mmm, I see you mention it at the start of the message. But "I get error" isn't helpful, it is better to report the errors you have...

 

I don't see a blatant error in the second code snippet, but again, telling us what error it is would help.

Edited by PhiLho (see edit history)
Link to comment
Share on other sites

This is the new code.

But i cant se the list from the db like i whant to...

 

And now i get some errors after the new edit in the code.

Fatal error: Cannot make static method ModuleCore::display() non static in class searchbyvehicle in modules\searchbyvehicle\searchbyvehicle.php on line 13

 

I get som more errors:

Table 'presta.ps_searchbyvehicle' doesn't exist

SELECT * FROM `ps_searchbyvehicle

 

And the modules is not instaling,,,,,,

 

Are i missing something ????

 

<?php
class searchbyvehicle extends Module
{
	private $_html = '';
	private $_postErrors = array();
	public  $path;
	private $_pagination = array(20,50,100,300);

function __construct()
{
	$this->name = 'searchbyvehicle';	
	$this->tab = 'front_office_features';
	$this->version = 0.1;
	$this->author = 'Niklas';

	$this->table = 'searchbyvehicle';
	 $this->className = 'Searchbyvehicle';

	 $this->lang = false;
	 $this->edit = true;
	 $this->view = true;
	 $this->delete = true;
	$this->deleted = true;
	$this->requiredDatabase = true;

	parent::__construct();

	$this->page = basename(__FILE__, '.php');
	$this->displayName = $this->l('Search by vehicle');
	$this->description = $this->l('Search tire and rims');

	$this->_errors = array();
	$this->path = $this->_path;

	$modDesc	  = $this->l('<fieldset>This module allows you to include as many banners as you like.');
	$modStatus	= $this->l('You can upload, order, activate or deactivate as many banners and select if you want them in the right or left columns.</fieldset>');
	$this->_html .= "<b>{$modDesc}</b><br /><br />
			{$modStatus}<br /><br /><br /><br />";

	$this->_select = 'SELECT Regnr FROM '._DB_PREFIX_.'searchbyvehicle ORDER BY Regnr DESC LIMIT 1';
	$this-> fieldsDisplay = array (
	'Regnr' => array('title' => $this->l('Regnr'), 'align' => 'center', 'width' => 25),
	'Fordonstyp' => array('title' => $this->l('Fordonstyp'), 'width' => 25),
	'Marke' => array('title' => $this->l('Marke'), 'width' => 80),
	'Modell' => array('title' => $this->l('Modell'), 'width' => 60),
	'Arsmodell' => array('title' => $this->l('Arsmodell'), 'width' => 120, 'maxlength' => 19));		

	parent::__construct();
}
	function getContent()
{
	$this->_html = '<h2>'.$this->displayName.'</h2>';		//Display Header
	if (!empty($_POST)){
		if (!sizeof($this->_postErrors))
			$this->_postProcess();
		else
			foreach ($this->_postErrors AS $err)
				$this->_html .= "<div class='alert error'>{$err}</div>";
	} else
		$this->_html .= "<br />";

	$this->display();
	return $this->_html;
}
public function display()
{
	global $cookie;

	if (isset($_GET['view'.$this->table]))
		$this->viewDetails();
	else
	{
		$this->getList((int)($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'DESC' : NULL);
		$this->displayList();
	}
}	
## INSTALL ##############################################
	function install()
	{
			if (parent::install() == false
							OR !$this->registerHook('home')
							OR $this->_createTables() == false
					)
					return false;
			return true;
	}
	/**
	*	   createTables()
	*	   Called when intalling
	*/
	public function _createTables()
	{	  
	$db = Db::getInstance();
			/*	  Create banners card table */
			$query = 'CREATE TABLE `'._DB_PREFIX_.'searchbyvehicle` (
							`Regnr` char(6) NOT NULL,
							`Fordonstyp` char(2) NOT NULL default "",
							`Marke` char(255) NOT NULL default "",
							`Modell` char(255) NOT NULL default "",
							`Arsmodell` char(255) NOT NULL default "",
							PRIMARY KEY (`Regnr`)
							) ENGINE=MyISAM DEFAULT CHARSET=utf8';
			$result = $db->Execute($query);
			if (!$result)
					return false;
			return true;
	}	  

	function uninstall()
	{
			$db = Db::getInstance();
			$query = 'DROP TABLE `'._DB_PREFIX_.'searchbyvehicle`';
			$result = $db->Execute($query);
			if (!$result)
					return false;

			if (!parent::uninstall())
					return false;
			return true;
	}
## HOOK ##############################################  
	 function hookHome($params)
	{
			global $cookie, $smarty;
			$smarty->assign(array(
					'searchbyvehicle_class' => 'home',
					'searchbyvehicle' => $this->getBanners('3'),
			));
			return $this->display(__FILE__, 'searchbyvehicle.tpl');
	}	  
}

 

I whant list them like customer list i BO

Untitled-1.jpg

Edited by spc (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...