custom library and helper not being called in database.php - php

I am using Codeigniter 3.1.2. I have a custom library and helper which i have auto loaded in autoload.php.
But all of these functions from helper and library not being called when I use these in database.php or in hooks (pre_controller) BUT SYSTEM'S LIBRARIES WORKS FINE THERE LIKE session, router etc etc
database.php
$CI = & get_instance();
echo $CI->nuts_lib->enc($_REQUEST['clid']);
return;
It shows following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: My_controller::$nuts_lib
Filename: config/database.php
Line Number: 76
Backtrace:
File: C:\xampp\htdocs\my_project\application\config\database.php Line:
76 Function: _error_handler
File: C:\xampp\htdocs\my_project\application\controllers\My_controller.php
Line: 18 Function: __construct
File: C:\xampp\htdocs\my_project\index.php Line: 280 Function:
require_once
I have tried through hooks still not worked. Help Please.

Found a solution. I can use native/system libraries direct in database.php and I have placed my encryption related code there. Now its working

See the flow of CI, Libraries are loaded before Database/Models
https://www.codeigniter.com/user_guide/overview/appflow.html

Related

Can't get the default controller of codeigniter to work in IIS

I am trying to host a codeigniter project on IIS Server but I can't get even the default controller to show instead what I receive is this below
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 101
Backtrace:
File: C:\inetpub\wwwroot\app\index.php
Line: 315
Function: require_once
I have web.config file, HTTP mappings, ISAPI, URL rewrite module and FastCGI all set but still the problem persist.
I will be very grateful if you guys can help me, am stranded.

Issue: Class 'CI_Config' not found in codeigniter

I am trying to run a codeIgniter project downloaded from 1and1.co.uk ....
But when I am browsing it showing this message:
An uncaught Exception was encountered
Type: Error
Message: Class 'CI_Config' not found
Filename: C:\xampp\htdocs\projectname\system\core\Common.php
Line Number: 196
Backtrace:
File: C:\xampp\htdocs\projectname\index.php
Line: 315
Function: require_once
I dont know why?
The class is ok in system/core/config.
Its version in system/core/codeigniter is 3.1.8.
can anyone tell me the reason pls?
Atleast some clue!
never ever faced anything like this before !
You have duplicate config file also in application/core folder which was causing this issue, there should be only one config in application/config folder.

How to load ion auth model in codeigniter HMVC

I am using the ion auth library for the CodeIgniter HMVC, I have copied all files from ion auth library to main CodeIgniter files but the controller, model, and views files copy to module directory Now it's showing me this error.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Auth::$ion_auth_model
Filename: libraries/Ion_auth.php
Line Number: 122
Backtrace:
File: /opt/lampp/htdocs/CI_Hmvc/application/libraries/Ion_auth.php
Line: 122 Function: _error_handler
File: /opt/lampp/htdocs/CI_Hmvc/application/libraries/Ion_auth.php
Line: 70 Function: __get
File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php
Line: 173 Function: _ci_load_library
File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php
Line: 192 Function: library
File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php
Line: 153 Function: libraries
File:
/opt/lampp/htdocs/CI_Hmvc/application/modules/home/controllers/Auth.php
Line: 9 Function: library
File: /opt/lampp/htdocs/CI_Hmvc/index.php Line: 315 Function:
require_once
could anybody tell me how to load the model, when I work as modules?
I believe the problem is that the library is not finding the model. Check inside ion auth library construct. Look for the line where it says
$this->load->model('ion_auth_model').
It should be line 122 since that's where the error is ocurring. In here you need to prefix the module name - where you have the ion_auth_model - to the model path so the loader class knows where to find it.
In your case if the module's name is directory, then 'directory/ion_auth_model'.
Check this solution https://stackoverflow.com/a/7003180/5785088, point 10, last item. Hope it helps.

Codeigniter Too many connection __construct()

I am using CI 3.X. Now in my app I using multiple database. Now my hosting server allows max 100 connections, So my app gets down.
In my database configurations I have kept PCONNECT to FALSE .
Now My Structure is as follow:
I have a base controller MY_Controller which extends to CI_Controller.
Then I have a Customer_Controller which extends to MY_Controller.
In Customer_Controller I load my secondary database. And this Customer_Controller lives in libraries folder.
All my other controller extend to this controller.
So where Am I going wrong ? Why does my MySQL sever gets this error ???
the error i get it:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/1040): Too many connections
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /application/core/MY_Controller.php Line: 7 Function:
__construct
File: /application/libraries/Admin_Controller.php Line: 7 Function:
__construct
File: /application/controllers/admin/Dashboard.php Line: 16 Function:
__construct
File: index.php Line: 315 Function: require_once
You will need to increase the value of max_connections in your MySQL configuration file. Possible location for the file is: /etc/my.cnf.
On the file increase the value of max_connections system variable:
[mysqld]
set-variable=max_connections=500
Alternatively, you can also turn off persistent connection from MySQL.
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent=Off

Unable to locate an appunto-auth model in CI 3

I'm trying to integrate appunto system to my application so I followed the full installation structure from the documentation but all time I got the next message :
An uncaught Exception was encountered
Type: RuntimeException
Message: Unable to locate the model you have specified: Pathmodel
Filename: /var/zpanel/hostdata/zadmin/public_html/git-backup_releasecandidate_net/system/core/Loader.php
Line Number: 344
Backtrace:
File: /var/zpanel/hostdata/zadmin/public_html/git-backup_releasecandidate_net/application/libraries/appunto-auth/Appunto_auth.php
Line: 24
Function: model
File: /var/zpanel/hostdata/zadmin/public_html/git-backup_releasecandidate_net/index.php
Line: 315
Function: require_once
If you are following this guide. You may need to change these lines in Appunto_auth library class.
$this->CI->load->model('appunto-auth/pathmodel');
$this->CI->load->model('appunto-auth/usermodel');
You may remove the appunto-auth folder from the path to the models since they will no longer be in that directory as we have moved it according to the guide.
$this->CI->load->model('pathmodel');
$this->CI->load->model('usermodel');
You may do the same if your app screams about the helper and config files on lines 22 and 15.

Categories