Jump to content

Hook throwing an error


CodePixel

Recommended Posts

So, it's been a while for me since i've done some plugins, now i'm trying getting back to it.. I've created plugin, for this plugin i've created a hook file, and no matter what i put inside of it, every time it throws error 

Quote

ParseError thrown with message "syntax error, unexpected '$variable' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST)"

that's how my hook file looks like:

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class hook28 extends _HOOK_CLASS_
{

$variable = "value";

}

 

Link to comment
Share on other sites

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class hook28 extends _HOOK_CLASS_
{

public $tvc_conn = \IPS\Db::i('tvcdb', array('sql_host' => 'test', 'sql_user' => 'user', 'sql_pass' => 'pass', 'sql_database' => 'dbname'));

}
Link to comment
Share on other sites

This isn't really related to hooks....you have a class there, and with a class you can have methods or properties. You cannot, however, execute code such as a db query when attempting to set a property value.

http://php.net/manual/en/language.oop5.php

If you can tell us what you're trying to achieve and which class you have hooked on to we can probably provide a little more guidance.

Link to comment
Share on other sites

8 hours ago, ~Jakso.` said:

I'm thinking that I don't get something. But here's what I did, I've created a public function inside hook class called dbconn, I've set up db connection there, website is not throwing any errors but I'm not sure if it's actually working..

If I understand what you're trying to do, it won't work like you expect it will. Adding in a public method to IPS\Db with your remote connection details there. Not going to work as you expect.. 

Don't hook into IPS\Db, hook into where you want the data and simply consolidate a method in you app / plugin that returns a DB instance connected to your remote  DB. Look at the docs I linked above that show how to set up the DB instance to an external DB as it is intended.

Link to comment
Share on other sites

So why not just use a second DB instance?  

	/**
	 * Get instance
	 *
	 * @param	mixed	$identifier			Identifier
	 * @param	array	$connectionSettings	Connection settings (use when initiating a new connection)
	 * @return	\IPS\Db
	 */
	public static function i( $identifier=NULL, $connectionSettings=array() )

Use a new identifier and pass the connection settings as second parameter

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...