I'm trying to access data on a external DB from magento from a Module, while using Magento ORM capabilites, I was able to do so by extending the:
Mage_Core_Model_Abstract and Mage_Core_Model_Resource_Db_Abstract classes as shown on this page:
http://www.solvingmagento.com/accessing-an-external-database-from-your-magento-module/
However when I'm try to use the getCollection() method on my model and I get "false" so I'm wondering if you can create collections based on the "Mage_Core_Model_Resource_Db_Abstract" class, I tried with "Mage_Core_Model_Resource_Db_Collection_Abstract" without any luck.
If it's not possible, does that mean that I have to change my module and use:
Mage_Core_Model_Mysql4_Abstract instead of Mage_Core_Model_Resource_Db_Abstract
As it seems like it has a "Mage_Core_Model_Mysq4_Collection_Abstract" class that works for what I want to do, as shown in:
http://fishpig.co.uk/magento/tutorials/create-external-database-connection/
I was trying to avoid Mage_Core_Model_Mysql4_Abstract as it sounds to me that it's exclusive for MySQL and I was hoping to keep the code more flexible.
Thanks,
Related
I am using Eloquent without Laravel and I'm wondering if there's a method which can be used (and does not rely on Laravel components) to integrate a caching method which then automatically caches all model queries (caching backend can be variable, say APCu or memcache).
I'm thinking that it should be possible to write a model base class which handles this but I'm not quite sure how I would go about implementing this. Does anybody have any ideas in this direction?
If you want to auto cache your query, you have to override the find(), findOrFail() , where() ... methods
Because of how Eloquent is built you can't simply add a method find() in your custom model class
https://laracasts.com/discuss/channels/eloquent/override-find-method/replies/72028
class MyCacheModel extends \Illuminate\Database\Eloquent\Model
{
// override methods as explained in previous link
// cache the result in redis for how long you want
}
Then in your model instead of extending Eloquent\Model, extends now from your MyCacheModel. With a bit of customization you can set how long queries will be cached and if a model shouldn't be cached then just use the Eloquent\Model.
WHMCS version 6 uses the Eloquent model.
Their using models documentation clearly states how to access the WHMCS database.
The problem I am experiencing is that I want to access my own model. I have multiple models, some that access WHMCS directly, and other that access a completely separate database.
To use their model, you do this:
...
use WHMCS\User\Client;
...
I tried simply to do this:
...
use WHMCS\User\Client;
use Radius\User\Logon;
...
I added my models to $root_folder/includes/classes/Radius/User/Logon.php mimicking the folder structure of WHMCS.
However, I get an error Fatal error: Class 'Radius\User\Logon' not found in /var/www/vhosts/snowball.co.za/wh6.snowball.co.za/modules/servers/radius/radius.php on line 543
I fully suspect I have to update Composer to recognise my own models, but I am not sure. What I do needs to be fully integrated with WHMCS and it must not break anything.
Does anyone have advice?
You may need to update your autoloaders.
Thank you for posting the solution - others will no doubt appreciate it.
I have a database I need to connect to remotely that is different then the Joomla database.
I can do this easily within other models but JModelAdmin is giving some issues as it seems to require JTable to function.
I have attempted to override the JTable instance to use my external database instead, however it does not seem to want to work and gets an error in "reset". My guess is JTable requires access to the core Joomla tables as well.
Is there any easy way to do this? Or is overriding the core the only option?
EDIT:
To clarify I can get Joomla to connect to the database and run queries. The only problem is that JTable refuses to initialize properly with an external database.
Here is my constructor in my model:
function __construct($config = array()){
$config['dbo'] = TireApiHelper::tireAPIDB();
parent::__construct($config);
}
This works in my list model but not my admin model. my list model has no need for a table class, however the controller needs to use the admin model to publish/unpublish, this is where the issue is. Even though JTable uses the currently set DB instance, it will return false with no Joomla error (according to code I should see a joomla error if $table returns false.
There are several ways you can achieve this, but the key point is to create a new database object. You can find the instructions on how to do that here. Once you have this object you could:
set your JTable class extension to use it via constructor or using the setDBO(...) method. See this.
choose to use this object and a query object without any JTable, like is explained in the Documentation site.
Cheers.
I want to add a function that will be used by several fixtures in my app, and it would be nice to be able to put it somewhere reflecting that it's an extension to CakeTestFixture. In a Model, I could do this by writing a Behavior or adding it to app_model.php. Is there a way to do this for fixtures?
I can always just add it to my static Utility class, but it would be nice to be able to structure it better.
Write an AppTestFixture which extends CakeTestFixture and include it in there. Obviously each fixture then has to extend your new class instead of Cake's one.
You know, in Symfony you get auto generated base class for database tables. I got an "user" table which stores users, passwords, and got already a pre-made template class for it. Its got login() logout() etc. routines (it just writes the session).
So, in different applications I would just write something like that:
class myUserClass extends UserClassTemplate
so I dont need to write login, logout again and again. But this time, I inherit a Symfony's base class - how can I inherit my template?
If you use Doctrine, you could write a custom behavior (or template) to achieve this thanks to the delegation of method calls (and not with multiple-inheritance, which is not available in php). See this example with... guess what? UserTemplate!