I got installed codeigniter 3 in a wampserver 3 with mysql, and the connection to the DB configured, and all is working well, models have connection and queries are returning data, however, when i'm using the profiler library, specially the function:
$this->output->enable_profiler(true);
It returns me the follow:
I just want to see the queries that were runned but is showing:
Database driver is not currently loaded
Any idea about how to solve this? It is like the profiler doesn't get that the DB is connected.
If you need more information ask me about it and thanks.
First of all this is completely necessary in the autoload.php:
$autoload['libraries'] = array('database');
And as annotation, Codeigniter doesn't support to show the queries runned when calling
$this->output->enable_profiler(true); // always check the difference between hyphen and underscore when calling functions
if you load the database connection on the CI_Model or any other model, it is completelly necessary loading the database connection over the controllers or main controller if want to see the queries runned.
You must be load database Library in config/autoload.php
$autoload['libraries'] = array('database');
Hope this solution will usefull to you.
Related
In Gorm we can use DB.Where to check the data of the user from the database for authentication. But I have to use Go Fiber so what can I use in place of DB.Where to check if the user is present in the database.
var user models.User
database.DB.Where("id = ?", claims.Issuer).(&user)
Well, as per your question gorm is working as a database also as a framework.
you can use go fiber as a framework but if you want to use the database you cannot use the database from fiber instead you have to use a database from which you can find the collection of the data in the database.
For example, you are using MongoDB with GoFiber so it will use the method of DB.Collection.FindOne()
In form Db.Where is used to find the database collection
Well, as per your question gorm is working as a database also as a framework.
you can use go fiber as a framework but if you want to use the database you cannot use the database from fiber instead you have to use a database from which you can find the collection of the data in the database.
For example, you are using MongoDB with GoFiber so it will use the method of DB.Collection.FindOne()
In form Db.Where is used to find the database collection
I have multiple database connected into my web app.
These are: write and read
I have this eloquent database query:
$users = User::whereIsAdmin(0)->get();
I want this db query to use the read database since by default my app is reading in the write database.
How would I do that?
Thanks!
I looked at the source code of Laravel Eloquent Models, and here:
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Model.php#L303
It says on should be used to change connections.
So:
User::on("read")->whereIsAdmin(0)->get();
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.
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.
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