Fatal error: Uncaught Error: Call to a member function check_main_module() on null on line 390
I have added a constructor and in the config, I have added modules as the library also.
function is_main_module_enabled($module) {
$result = $this->Modules_model->check_main_module($module);
return $result;
}
**`In Modules_model.php`**
function check_main_module($module) {
$this->load->library('ptmodules');
return $this->ptmodules->is_main_module_enabled($module);
}
**`In ptmodules file`**
function is_main_module_enabled($module) {
$this->_ci->db->select('page_id');
$this->_ci->db->where('page_status', 'Yes');
$this->_ci->db->where('page_slug', $module);
$rows = $this->_ci->db->get('pt_cms')->num_rows();
if ($rows > 0) {
return true;
}
else {
return false;
}
}
Try This,
Controller:
function is_main_module_enabled($module) {
$this->load->model('Modules_model');
$result = $this->Modules_model->check_main_module($module);
return $result;
}
Library:
function is_main_module_enabled($module) {
$CI = & get_instance();
$CI->db->select('page_id');
$CI->db->from('pt_cms');
$CI->db->where('page_status', 'Yes');
$CI->db->where('page_slug', $module);
$rows = $CI->db->get();
if ($rows->num_rows() > 0) {
return true;
}
else {
return false;
}
}
Related
I have face this Fatal error: problem in local.
$rr = $this->CI->db->query("select * from $table $condition ");
$mm = $rr->num_rows();
if ($mm>0) {
return 1;
} else {
return 0;
}
<?php
$this->db->select("your stuff");
$query = $this->db->get("your table");
if($query->num_rows() > 0 ) {
return 1;
}
else {
return 0;
}
?>
$this->CI->db->query("select * from $table $condition ");
remove CI and
$this->db->query("select * from $table $condition ");
First have you autoload the database
$autoload['libraries'] = array('database');
If a your trying to load a library then use the $CI instance http://www.codeigniter.com/user_guide/general/ancillary_classes.html#get-instance
application > libraries > Example.php
<?php
class Example {
protected $CI;
public function __construct() {
$this->CI =& get_instance();
}
public function somename() {
$query = $this->CI->db->query("select * from $table $condition ");
if ($query->num_rows() > 0) {
return 1; // return true;
} else {
return 0; // return false;
}
}
}
If on models
application > models > Example_model.php
<?php
class Example_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function somename() {
$query = $this->db->query("select * from $table $condition ");
if ($query->num_rows() > 0) {
return 1; // return true;
} else {
return 0; // return false;
}
}
}
Update one CI core file and resolve your error:
Go to : System/database/ and edit DB_active_rec.php file
Go to line no 990 and see blow code
if ($query->num_rows() == 0)
{
return 0;
}
Update to
if (!$query || $query->num_rows() == 0)
{
return 0;
}
Hope resolved your num_rows() issue.
class Site_m extends MY_Model {
protected $_table_name = 'setting';
protected $_primary_key = 'option';
protected $_primary_filter = 'intval';
protected $_order_by = "option asc";
function __construct() {
parent::__construct();
}
function get_site($id) {
$compress = array();
$query = $this->db->get('setting');
foreach ($query->result() as $row) {
$compress[$row->fieldoption] = $row->value;//here I am getting error
}
return (object) $compress;
}
}
/* End of file site_m.php */
This is fix in core CI-2
File
\system\database\DB_driver.php
Line in code
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_driver.php#L659
replace FALSE before end code
// Run the Query
if (FALSE === ($this->result_id = $this->simple_query($sql)))
{
if ($this->save_queries == TRUE)
{
$this->query_times[] = 0;
}
// This will trigger a rollback if transactions are being used
$this->_trans_status = FALSE;
if ($this->db_debug)
{
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();
// We call this function in order to roll-back queries
// if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Log and display errors
log_message('error', 'Query error: '.$error_msg);
return $this->display_error(
array(
'Error Number: '.$error_no,
$error_msg,
$sql
)
);
}
return FALSE;
}
To
// Run the Query
if (FALSE === ($this->result_id = $this->simple_query($sql)))
{
if ($this->save_queries == TRUE)
{
$this->query_times[] = 0;
}
// This will trigger a rollback if transactions are being used
$this->_trans_status = FALSE;
if ($this->db_debug)
{
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();
// We call this function in order to roll-back queries
// if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Log and display errors
log_message('error', 'Query error: '.$error_msg);
return $this->display_error(
array(
'Error Number: '.$error_no,
$error_msg,
$sql
)
);
}
$CR = new CI_DB_result();
return $CR;
}
Default should be return object empty
$CR = new CI_DB_result();
return $CR;
On my multiple upload library, I have a set error function.
On my upload function I use a in_array to check file extensions. If the in_array detects error it displays multiple error messages correct.
The problem I am having is for some reason when I use return FALSE; under the $this->set_error('file_extension_not_allowed') then will on display one message. Not sure why return FALSE limits error messages.
Question: How is it possible to use my return false but be able to display multiple message correct.
<?php
class Multiple_upload {
public $set_errors = array();
public function __construct($config = array()) {
$this->CI =& get_instance();
$this->files = $this->clean($_FILES);
empty($config) OR $this->set_config($config);
}
public function set_config($config) {
foreach ($config as $key => $value) {
$this->$key = $value;
}
return $this;
}
public function upload($field = 'userfile') {
$allowed_extension = explode('|', $this->allowed_types);
if (empty($this->upload_path)) {
$this->set_error('upload_path_not_set', 'upload_path_check');
return FALSE;
}
if (!realpath(FCPATH . $this->upload_path)) {
$this->set_error('upload_path_in_correct', 'location_check');
return FALSE;
}
if (!empty($this->files[$field]['name'][0])) {
foreach ($this->files[$field]['name'] as $key => $value) {
$this->file_name = $this->files[$field]['name'][$key];
$get_file_extension = explode('.', $this->files[$field]['name'][$key]);
$this->get_file_extension_end = strtolower(end($get_file_extension));
$array_1 = array(
$allowed_extension,
);
$array_2 = array(
$get_file_extension[1],
);
if (!in_array($array_2, $array_1)) {
$this->set_error('file_extension_not_allowed', 'extension_check');
return FALSE;
}
}
return $this;
}
}
public function set_error($message, $type) {
$this->CI->lang->load('upload', 'english');
$this->error_message[] = $this->CI->lang->line($message);
return $this;
}
public function display_error_messages($open_tag = '<p>', $close_tag = '</p>') {
foreach($this->error_message as $msg) {
var_dump($msg);
}
}
public function clean($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$this->clean($key)] = $this->clean($value);
}
} else {
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
}
return $data;
}
}
Maybe this can help...
public function upload($field = 'userfile')
{
$allowed_extension = explode('|', $this->allowed_types);
if (empty($this->upload_path))
{
$this->set_error('upload_path_not_set', 'upload_path_check');
return FALSE;
}
if (!realpath(FCPATH . $this->upload_path))
{
$this->set_error('upload_path_in_correct', 'location_check');
return FALSE;
}
if (!empty($this->files[$field]['name'][0]))
{
$check_error = 0;//added this
foreach ($this->files[$field]['name'] as $key => $value)
{
$this->file_name = $this->files[$field]['name'][$key];
$get_file_extension = explode('.', $this->files[$field]['name'][$key]);
$this->get_file_extension_end = strtolower(end($get_file_extension));
$array_1 = array(
$allowed_extension,
);
$array_2 = array(
$get_file_extension[1],
);
if (!in_array($array_2, $array_1))
{
$this->set_error('file_extension_not_allowed', 'extension_check');
$check_error++;
}
}
if($check_error > 0 )
{
return FALSE;
}
return $this;
}
}
I am sitting in my chair for 2 hours and I cannot find what is wrong with this. I'm new to codeigniter things and I only got this error for the first time. Can you guys help me? Any help would be appreciated. Thanks in advance so much ...
****A PHP Error was encountered
Severity: Notice
Message: Undefined property: Facebook_model::$facebook
Filename: models/facebook_model.php
Line Number: 15
Fatal error: *Call to a member function getUser() on a non-object in C:\xampp\htdocs\hpbge\hpbge_files\system\hpbgestrong text_web_app\models\facebook_model.php on line 15*****
<?php
class Facebook_model extends Model {
public function get_user() {
$query = $this->facebook->getUser();
if ($query) {
$data['is_true'] = TRUE;
$data['facebook_uid'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function get_access_token() {
$query = $this->facebook->getAccessToken();
if ($query) {
$data['is_true'] = TRUE;
$data['access_token'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function get_api_secret() {
$query = $this->facebook->getApiSecret();
if ($query) {
$data['is_true'] = TRUE;
$data['api_secret'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function get_app_id() {
$query = $this->facebook->getApiSecret();
if ($query) {
$data['is_true'] = TRUE;
$data['app_id'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function get_logout_url() {
$query = $this->facebook->getLogoutUrl(array('next' => base_url()));
if ($query) {
$data['is_true'] = TRUE;
$data['logout_url'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function get_signed_request() {
$query = $this->facebook->getSignedRequest();
if ($query) {
$data['is_true'] = TRUE;
$data['signed_request'] = $query;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function set_access_token($access_token) {
$query = $this->facebook->setAccessToken($access_token);
if ($query) {
$data['is_true'] = TRUE;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function set_api_secret($app_secret) {
$query = $this->facebook->setApiSecret($app_secret);
if ($query) {
$data['is_true'] = TRUE;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
function set_app_id($app_id) {
$query = $this->facebook->setAppId($app_id);
if ($query) {
$data['is_true'] = TRUE;
return $data;
} else {
$data['is_true'] = FALSE;
return $data;
}
}
//function is formatted for the following
//https://graph.facebook.com/ID/CONNECTION_TYPE?access_token=123456
function get_facebook_object($object, $facebook_uid, $access_token) {
$fb_connect = curl_init();
curl_setopt($fb_connect, CURLOPT_URL, 'https://graph.facebook.com/'.$facebook_uid.'/'.$object.'?access_token='.$access_token);
curl_setopt($fb_connect, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($fb_connect);
curl_close($fb_connect);
$result = json_decode($output);
if (isset($result->error)) {
$data['is_true'] = FALSE;
$data['message'] = $result->error->message;
$data['type'] = $result->error->type;
$data['code'] = $result->error->code;
return $data;
} else {
$data['is_true'] = TRUE;
$data['data'] = $result->data;
return $data;
}
}
}
It seems that you have not loaded the facebook library put this line in your construct of model file
$this->load->library('facebook', array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET'
));
and make sure that you have put the facebook.php and base_facebook.php in libraries folder under application.
I am checking a country name already exist in my database i used callback but it doest not shoot any error
$this->form_validation->set_rules('country_name', 'Country Name',
'trim|required|xss_clean|callback_check_exist');
This is my controller function
function check_exist($country_name)
{
$this->countrymodel->country_exists($country_name);
}
and this is my model
function country_exists($key)
{
$this->db->where('country_name',$key);
$this->db->from($this->dbname);
$query = $this->db->get();
if ($query->num_rows()> 0){
return true;
}
else{
return false;
}
}
The callback function should return a value and set a message:
function check_exist($country_name)
{
if (!$this->countrymodel->country_exists($country_name)) {
$this->form_validation->set_message('check_exist', 'an error message');
return FALSE;
}
else {
return TRUE;
}
}
function empAll()
{
$this->db->where('id',$id);
$q = $this->db->get('employee');
if($q->num_rows()>0)
{
foreach($q->result() as $rows)
{
$data[]=$rows;
}
return $data;
}
Generally we pass id in the Url:
Base_url()/index.php/empAll/25. Now codeigniter automatecaly pass the $id = 25 in the method. In case id not received it will assign the id by 0 and then you will not get this error.
function empAll()
{
$q = $this->db->where('id',$this->input->post('id'))
->get('employee');
if($q->num_rows()>0)
{
foreach($q->result() as $rows)
{
$data[]=$rows;
}
}
return $data;
}