Can I extend the DB library of CodeIgniter 2? - codeigniter

I want to add custom data to the insert method of the db library to automatically do some timestamp work and other processing. I know I can extend controller and model defaults with MY_, but what about the DB?

This isnt the right answer, because you can extend your CI Database class, i did it!
Just follow this tut and you will get it working!
https://github.com/EllisLab/CodeIgniter/wiki/Extending-Database-Drivers
im just have problems trying to use two database connections when the second connection is loaded with $this->db->load(), just had this problem, everyelse work like a charm!

No: see http://codeigniter.com/user_guide/general/creating_libraries.html, there is an explicit warning that the DB class can't be extended.

Related

PrestaShop working with Doctrine & Entites

Hello :) On start: I use PrestaShop 1.7.6.2 and MySQL 5.6 and PHP 7.2
I want to create a module on new way with Symfony Controller and Entites without ObjectModel (beacouse like say one of develoeper of PrestaShop: Pablo Borowicz - ObjectModel is deprecated)
So on start I create simple module available at the link
https://github.com/DarkSidePro/testmodule
Controller and routing works perfect the problem is when I try use enity manager
$entityManager = $this->container->get('doctrine.orm.entity_manager');
$testRepository = $entityManager->getRepository(TestmoduleTest::class);
$test = $testRepository->findAll();
And I have error like that:
The class 'DarkSide\Testmodule\Entity\TestmoduleTest' was not found in the chain configured namespaces PrestaShopBundle\Entity
Maybe I doing something wrong? But doc of prestashop of coures is suck about new way of creating a PrestaShop modules
Looking 4 help :)
Thx all :)
The PrestaShop documentation is a completely mess concerning the handling of the Symfony repositories.
Doctrine is looking (by the auto_mapping orm configuration attribute) for the presence of your entity under the Prestashop Entity namespace, so given that your TestmoduleTest entity isn't there, it cannot be found and therefore loaded.
You may have to register your entity under the following namespace : namespace PrestaShop\Module\Testmodule\Entity;
You'll be able to find more about how to create your own repository class inside the official productcomments module here.
Ok the problem is on other way :)
In this case i have problem with my Repository class (probably with constructor of this class)
when I deleted them module start work
Problem solved :)

Laravel Auditing AuditableTransitionException Error on Morphmap on transitionTo()

I am able to successfully record changes to classes, and return what has been changed (not including many-to-many). However, I am unable to revert back any change using the built-in new transitionTo() method.
I get the following error on all classes:
Expected Auditable type App\XYZ, got XYZ instead
I have all of my morphable classes (which are all I am using for tracking audits) attached correctly within AppServiceProvider in a morphmap like so:
\Illuminate\Database\Eloquent\Relations\Relation::morphMap([
'Employee' => \App\Employee::class,
];
All classes work correctly with all other Laravel morphTo methods.
The auditable code looks like it is tripping the error in line 467 of the Auditable class:
if (!$this instanceof $audit->auditable_type) {}
It doesn't appear to be looking to the map for any of the morphed classes. Or, I could be totally missing something of course!
Any help on how to get this to work using the auditing method -- has anyone gotten this to work with standard morph classes? (It will of course revert the class manually by looping on the old fields and saving the object).
Using Laravel 5.5 and the latest version (5.0) of Laravel-Auditing.
Sent a note to the developer - this was in fact a bug. Vendor code was needed to include morphMapped objects.
Developer at Laravel Auditing responded within an hour and had a fix a few hours later. I can confirm this is now functioning as expected. Outstanding support.

Laravel 4: Dynamic db selection using Capsule

Just trying to understand how Capsule works in laravel. Everything works correctly where it is defined, however, as soon as a new page is opened it again take backs the old connection information instead of the new connection which is defined.
I believed setAsGlobal() basically makes it available for that particular session atleast, however, I guess I am conceptually wrong here.
It would be really nice if someone can guide through the right way to make the new database connection available globally VIA CAPSULE, there are various other ways, however this seems more promising.
It would be really nice if someone could explain the following commands in more simpler way (the comments are written as per in the documentation, however, something above that would be really nice):
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Set the cache manager instance used by connections... (optional)
$capsule->setCacheManager(...);
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
Any help would really be appreciated. Thank you.
Check my answer at https://stackoverflow.com/a/34837068/1216285 to use Capsule out of Laravel scope in your app. Since all the laravel components are decoupled and served as independent components in laravel project, you can use them in your app easily.

Sample of how to create and save new entity, Breezejs

Im trying to create a very basic Todo-entity from the Breeze example.. Im doing:
manager.createEntity("Todo",{Description:"Test",Id:32,IsDone:false});
But I keep getting an error where the console tells me that it couldnt find the Type "Todo".. I have tried all types I can possibly think of..
Could anyone please provide me with an example of how to create an entity for the breeze WebApiSample.. cause this is driving me nuts..
Thanks alot!
Breeze needs metadata in order to create an entity of any type. That metadata can either be returned from the server or created locally. My guess is that you haven't yet done either of these. Metadata from the server is usually automatically fetched by Breeze during its first query against the server. Alternatively you can cause it to be fetched directly via the MetadataStore.fetchMetadata method.
Hope this helps.

using doctrine with codeigniter

I am planning to use doctrine to write a module of my app which is built with codeigniter.
I have a very basic question :
lets say I have a table called "user", with doctrine generate-models from db, 3 classes are generated BaseUser.php, User.php and UserTable.php. Now as I saw in the examples they use User class straigtaway. Should I be doing this ? I need additional business functionality for the user objects. So should I create a codeigniter model user_model and then use User class inside it (aggregation) or somehow extend user class ( i dont know how this will be done as user_model extends model)
Am little confused on this one and cannot locate any appropriate literature for the same.
Any help would be appreciated.
thanks in advance,
For anyone who is interested - I’ve posted up a project starter on my blog - a dev ready incorporation of the following technologies:
ExtJS : client side JS library,
CodeIgniter : presentation + domain tier,
Doctrine : ORM data layer framework
Some features of this project starter are:
- CodeIgniter Models have been replaced with Doctrine Records
- Doctrine is loaded into CI as a plugin
- RoR type before and after filters….
- Doctrine transactions automatically wrapped around every action at execution time (ATOMIC db updates)
Basic Role based security (I think Redux may be in there as well?)
Simply extract, hook up the database.php config file and viola…. You can start coding your layouts, views and models. Probably a few things to iron out - but enjoy!
Hope it helps
GET IT AT: http://thecodeabode.blogspot.com
Check out this info on Doctrine_Table class.
To your 3 generated files:
BaseXXX.php:
Holds the definition of your models so that Doctrine is able to handle the operations on the database. This class tells the ORM what colums are available, their types, advaned functions (like Timestampable,...) and more. You should not put your own data into this file since it will be over-written when re-creating the models from the database.
XXX.php:
Your actual model. This won't be re-created with each new generation process and this is were you keep most of your code. You can overwrite functions of the BaseXXX.php if you have to.
XXXTable.php:
Check my link from the top, This gives you access to the table itself. Personally, I do not use it that often since I put most of the code into XXX.php.
Of course you can create new classes and use them inside your XXX.php file. In order to actually do something with the data (save, read,...) you need classes that are connected (exteneded) from Doctrine's classes.
edit: also check this on a more infos with extending from the Doctrine_Table class

Resources