• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XenForo_Application::get('db');

cedivad

Active member
#1
It looks like that i can't use that in ./library/XenForo/FrontController.php
Is this a bug or it is loaded after? Can i load it manually to use it in that class?

Thank you.
 

dmnkhhn

Active member
#2
Does that help: #5 ?

Maybe it would be a lot easier if you post what you want to achieve. Modifying the FrontController.php is not the best way to do things.
That's the reason why you create your own controller that extends the XenForo_Controller*_Abstract.
 

cedivad

Active member
#3
Thank you. However and unfortunately, by using
PHP:
$hashInfo = $this->_getDb()->fetchRow('
i get
Fatal error: Call to undefined method XenForo_Router::_getDb() in /Applications/MAMP/htdocs/xf/library/XenForo/Router.php on line 128

I'm using the do-it-yourself way by calling an own istance of mysql, slower but will work.
PHP:
include(dirname(__FILE__) . '/../config.php');
$link = mysql_connect ($config['db']['host'], $config['db']['username'], $config['db']['password']);

etc
I have to edit the front controller, i'm tring to edit the thread urls from http://xenforo.com/community/threads/xenforo_application-get-db.5471/ to "http://xenforo.com/community/fR2Ga" and i'm almost done ;) - i know it may seem useless for you but i want it :D
I don't know how to use the plugin system and editing the files seems the better way to go as of now that there are no docs and i've to edit only a cupple of files ;)
 

dmnkhhn

Active member
#6
Over the next weeks we will get more information about how XenForo works and I am confident that we will learn how to do such things properly. :)

The reason why the code I suggested is not working is that $this refers (in your case) to the XenForo_Router and a router doesn't have such a method.
 

cedivad

Active member
#8
Searching for the _getDb definition, i find this:
PHP:
	protected function _getDb()
	{
		if ($this->_db === null)
		{
			$this->_db = XenForo_Application::get('db');
		}

		return $this->_db;
	}
Than i suppose that if XenForo_Application::get('db') don't work in the Router or Input classes calling the getDb function is useless.
 

dmnkhhn

Active member
#9
That's why you should use your own controller and a model because only the model (AFAIK) has access to the database by using
PHP:
$this->_getDb()->fetchWhatever();
There are several models, the XenForo_Model seems to be the basic one with basic methods (like fetchCol()) but there are specific ones like the XenForo_Model_Post with the getPostsByIds()-method. :)

You will find all available models in /upload/library/XenForo/Model/ - each file is a specific model.