Call to undefined method CI_DB_mysql_driver::get() - codeigniter

I got the error.
Call to undefined method CI_DB_mysql_driver::get()
I find out to solve it but I couldn't.I already loaded database library in autoload.php .
$autoload['libraries'] = array('session', 'Template', 'email','database');
Model.php
$query = $this->db->get('team');

in config database.php enable $query_builder = TRUE;

Related

PHP Codeigniter 3.1.10: Unable to update session data

Happen to be stuck since almost a day. Scoured in google searching as to why this isn't working as expected, and also couple of answered questions in stackoverflow, but couldn't figure out as to why it's not working.
Basically i am setting session data during login, like
foreach($response as $item) {
$sess_array = array(
'user_id' => $item->id,
'photo' => $item->user_pic,
);
}
// Create session
$this->session->set_userdata('logged_in', $sess_array);
And now I am attempting to update a particular variable named 'photo'.
$this->session->set_userdata('photo', $new_name);
And when I try to display the value of the session variable 'photo' in my view, it still shows the old value and not the updated value.
Below are the entries from config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH . 'cache/sessions/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
Codeigniter version 3.1.10
OS Windows 10
Please help.
First of all just check in you autoload.php did you load the session library or not.
or else load session library in your controller. $this->load->library('session');
foreach($response as $item) { // looping your obj $response
$sess_array = array( // set an array
'user_id' => $item->id,
'photo' => $item->user_pic,
);
}
print_r($sess_array); you will get the last element of you $response obj here.
// Create session
$this->session->set_userdata('logged_in', $sess_array); // here you are setting the last obj of $response in you session logged_in
`$this->session->set_userdata('photo', $new_name);` // here you store an variable $new_name in session `photo`
redirect from your controller current function to new function after setting the session.
for example.
class session extend CI_Controller{
function set_session(){
$new_name = 'xyz';
$this->session->set_userdata('photo', $new_name);
return redirect('session/get_session');
}
function get_session(){
$this->load->view('sample');
}
}
In your view sample.php
<body><h1>
<?php
echo $this->session->userdata('photo');
// here you got out put 'xyz'
?>
</h1></body>
Hope you can find the issue where you go wrong.

Non-static method Maatwebsite\Excel\Readers\LaravelExcelReader::all() should not be called statically, assuming $this from incompatible context

I'm getting this error whenever trying to upload and excel file
My function is
use Illuminate\Support\Facades\Input;
use Excel;
function:-
public function importProduct(){
$file = Input::file('file');
$file_name = $file->getClientOriginalName();
$file->move('excelData/',$file_name);
$result = \Excel::load('excelData/'.$file_name, function($reader){
$reader::all();
})->get();
return json_encode($result);
}
$result = \Excel::load('excelData/'.$file_name, function(LaravelExcelReader $reader){
$reader::all();
})->get();
I think this should work, if you are using 2.1 version of excel
Two Steps
1.First get the Path
$path = $request->file('file')->getRealPath();
2. Get data in array
$data = Excel::load($path)->get();
Now we can Play with data array

CI Not create session

$veri = array("uye_kadi" => $this->input->post('kadi'), 'oturum' => TRUE);
$this->session->set_userdata($veri);
First make sure that you have included session library
either from autoload config file:
$autoload['libraries'] = array('session');
or from controller:
$this->load->library('session');
and then
replace your code with :
$veri = array("uye_kadi" => $this->input->post('kadi'), 'oturum' => TRUE);
$this->session->set_userdata('sess_var_name',$veri);
echo $this->session->userdata('sess_var_name');
Array with can be used as:
$ar = array('user_id'=>900,
'username'=>'John Doe');
$this->session->set_userdata('user_details',$ar);
$this->session->userdata('user_details','user_id'); //Return 900;
hope it will help!

cannot connect to database using codeigniter

I know this sounds so repost several times. But I cannot get it resolved.
I tried to connect my application to mysql, these are what I have tried (I tried only one out of these options, not both):
$autoload['libraries'] = array('database'); on application\config\autoload.php, but I got Fatal error: Call to a member function get() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_models.php on line 15
$this->load->database(); on application\models\My_models.php on __construct() (also I added parent::__construct(), but I got Fatal error: Call to a member function database() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_model.php on line 7
So, what could be wrong here?
EDIT:
this is my database.php looks like.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'trial';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
RESOLVED!!!
After all, this is all because of the autocomplete on Eclipse I added on system/core/Controller.php and system/core/Model.php.
Hmm.., I think you don't have to add
$this->load->database();
on your My_models.php, coz as I know it will be automatically connected to the database as you set on the database.php file. So, remove it from My_models.php file & try again.
Hope it helps :)
In you My_models.php you shouldn't be calling $this->load->database(); should just have:
class My_models extends CI_Model {
/**
* Constructor
*/
function __construct()
{
parent::__construct();
}
function something(){
// your model code goes here
}
}
Also you only need to enable the autoload and you are good to go (keeping in mind that the MYSQL library needs to be loaded for PHP.
And you might have an error here (don't see your code so not sure):
Fatal error: Call to a member function get() on a non-object in
/Users/zakkafm/Sites/CodeIgniter/application/models/My_models.php on line 15

getting setup model

I want create new table out of magento, in interface, without inheriting setup class. I tried to get resource model of setup. This didn't work:
require_once 'app/Mage.php';
Mage::init();
$setup = Mage::getResourceModel('catalog/setup');
I was also thinking about Mage::getResourceModel('core/resource_setup') but i have an error: Fatal error: Call to a member function startSetup() on a non-object in C:\xampp\
htdocs\LPP_MAGENTO_EE_CUSTOM\app\code\core\Mage\Core\Model\Resource\Setup.php on
line 944
Do you have any idea?
(I saw this question but it doesn't work for me)
I did it with $setup = Mage::getModel('eav/entity_setup', 'core_setup') example for create new attribute for Category within my code:
require_once 'app/Mage.php';
Mage::init();
$setup = Mage::getModel('eav/entity_setup', 'core_setup');
$setup->addAttribute('catalog_category', 'xxx', array(
...
));

Resources