CodeIgniter Forums
why models are not loading in autoload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: why models are not loading in autoload (/thread-75049.html)

Pages: 1 2


why models are not loading in autoload - Lohith c - 12-13-2019

i know the basic concept model name should start with small letter in autoload

i need a detailed answer


RE: why models are not loading in autoload - ciadmin - 12-13-2019

You're a bit skimpy on details supporting your claim that models aren't autoloaded.

application/config/autoload.php ...
$autoload['model'] = array('customer');

tells CodeIgniter to look for the class "Customer" inside application/models/Customer.php

Note the UCfirst convention.


RE: why models are not loading in autoload - Lohith c - 12-13-2019

(12-13-2019, 01:54 PM)ciadmin Wrote: You're a bit skimpy on details supporting your claim that models aren't autoloaded.

application/config/autoload.php ...
$autoload['model'] = array('customer');

tells CodeIgniter to look for the class "Customer" inside application/models/Customer.php

Note the UCfirst convention.
i knew it  but some model in autoload it will not work and the same model will work when i call it in controller and some are vice versa
why this has been happen and give me a correct link  to download the php and codeigniter should perfectly in that


RE: why models are not loading in autoload - ciadmin - 12-14-2019

Please provide some sample code that isn't working


RE: why models are not loading in autoload - Lohith c - 12-14-2019

this model is not working please guide me

controller--------

<?php if (!defined('BASEPATH'))exit('No direct script access allowed');


class Admin extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->database();
$this->load->library('session');

}


function vacancy($param1 = '', $param2 ='', $param3 =''){

if ($param1 =='insert'){

$this->load->vacancy_model->insertVacancyFunction();
$this->session->set_flashdata('flash_message', get_phrase('Data saved successfully'));
redirect(base_url(). 'admin/vacancy', 'refresh');

}

if ($param1 == 'update'){


$this->vacancy_model->updateVacancyFunction($param2);
$this->session->set_flashdata('flash_message', get_phrase('Data updated successfully'));
redirect(base_url(). 'admin/vacancy', 'refresh');

}

if($param1 == 'delete'){


$this->vacancy_model->deleteVacancyFunction($param2);
$this->session->set_flashdata('flash_message', get_phrase('Data deleted successfully'));
redirect(base_url(). 'admin/vacancy', 'refresh');

}


$page_data['page_name'] = 'vacancy';
$page_data['page_title'] = get_phrase('Manage Vacancy');
$page_data['select_vacancy'] = $this->db->get('vacancy')->result_array();
$this->load->view('backend/index', $page_data);

}

}

model------>



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Vacancy_model extends CI_Model {

function __construct()
{
parent::__construct();

}


// The function below insert into vacancy table //
function insertVacancyFunction(){

$page_data = array(
'name' => $this->input->post('name'),
'number_of_vacancies' => $this->input->post('number_of_vacancies'),
'last_date' => $this->input->post('last_date'),
);

$this->db->insert('vacancy', $page_data);
}

// The function below update vacancy table //
function updateVacancyFunction($param2){
$page_data = array(
'name' => $this->input->post('name'),
'number_of_vacancies' => $this->input->post('number_of_vacancies'),
'last_date' => $this->input->post('last_date'),
);

$this->db->where('vacancy_id', $param2);
$this->db->update('vacancy', $page_data);
}

// The function below delete from vacancy table //
function deleteVacancyFunction($param2){
$this->db->where('vacancy_id', $param2);
$this->db->delete('vacancy');
}


}


view --->



<div class="row">
<div class="col-sm-5">
<div class="panel panel-info">
<div class="panel-heading"> <i class="fa fa-plus"></i>&nbsp;&nbsp;<?php echo get_phrase('add_vacancy'); ?></div>
<div class="panel-body table-responsive">



<?php echo form_open(base_url() . 'admin/vacancy/insert', array('class' => 'form-horizontal form-goups-bordered validate'));?>


<div class="form-group">
<label class="col-md-12" for="example-text"><?php echo get_phrase('position_name');?></label>
<div class="col-sm-12">
<input type="text" class="form-control" name="name" required value="" autofocus />
</div>
</div>

<div class="form-group">
<label class="col-md-12" for="example-text"><?php echo get_phrase('number_of_vacancies'); ?></label>

<div class="col-sm-12">
<input type="number" class="form-control" name="number_of_vacancies" min="0" required value="" />
</div>
</div>

<div class="form-group">
<label class="col-md-12" for="example-text"><?php echo get_phrase('last_date_of_application'); ?></label>

<div class="col-sm-12">
<input type="date" class="form-control" value="<?php echo date('Y-m-d');?>" name="last_date" />
</div>
</div>

<div class="form-group">
<button type="submit" class="btn btn-block btn-info btn-rounded btn-sm"><i class="fa fa-plus"></i>&nbsp; <?php echo get_phrase('add_vacancy'); ?></button>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>



<!----CREATION FORM ENDS-->
<div class="col-sm-7">
<div class="panel panel-info">
<div class="panel-heading"> <i class="fa fa-list"></i>&nbsp;&nbsp;<?php echo get_phrase('list_vacancies'); ?></div>



<div class="panel-wrapper collapse in" aria-expanded="true">
<div class="panel-body table-responsive">
<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th><div>#</div></th>
<th><div><?php echo get_phrase('position_name'); ?></div></th>
<th><div><?php echo get_phrase('number_of_vacancies'); ?></div></th>
<th><div><?php echo get_phrase('last_date_of_application'); ?></div></th>
<th><div><?php echo get_phrase('options'); ?></div></th>
</tr>
</thead>
<tbody>

<?php
$counter = 1; foreach($select_vacancy as $key => $vacancy):?>

<tr>
<td><?php echo $counter++;?></td>
<td><?php echo $vacancy['name'];?></td>
<td><?php echo $vacancy['number_of_vacancies'];?></td>
<td><?php echo $vacancy['last_date'];?></td>
<td>

<a href="#" onclick="showAjaxModal('<?php echo base_url(); ?>modal/popup/edit_vacancy/<?php echo $vacancy['vacancy_id'];?>');"
class="btn btn-info btn-circle btn-xs"><i class="fa fa-edit" style="color:white"></i></a>

<a href="#" class="btn btn-xs btn-circle btn-danger" onclick="confirm_modal('<?php echo base_url(); ?>admin/vacancy/delete/<?php echo $vacancy['vacancy_id'];?>');">
<i class="fa fa-times" style="color:white"></i> </a>



</td>
</tr>

<?php endforeach;?>
</tbody>
</table>


</div>
</div>
</div>
</div>
</div>
<!----TABLE LISTING ENDS--->


RE: why models are not loading in autoload - InsiteFX - 12-14-2019

To load a model in a Controller it is done like this.

PHP Code:
// load in a controller'
$this->load->model('modelName''aliasName'); 

Also to access a method in the controller.

PHP Code:
// load in controller and access method.
$this->load->('vacancy_model');
$this->vacancy_model->insertVacancyFunction(); 

Give that a try


RE: why models are not loading in autoload - Lohith c - 12-14-2019

(12-14-2019, 09:13 AM)InsiteFX Wrote: To load a model in a Controller it is done like this.

PHP Code:
// load in a controller'
$this->load->model('modelName''aliasName'); 

Also to access a method in the controller.

PHP Code:
// load in controller and access method.
$this->load->('vacancy_model');
$this->vacancy_model->insertVacancyFunction(); 


files are not loading if i did like above 



RE: why models are not loading in autoload - InsiteFX - 12-14-2019

I would re-download CodeIgniter and install a clean new copy and see if that will fix it.

Otherwise it sounds like something is corrupted in your directory structure.

I always use the development branch and I use both CI 3 and CI 4 with not problems.


RE: why models are not loading in autoload - Lohith c - 12-14-2019

i just created two model with different name one is loading without error and another one is not and all the sytaxes are correct may i know what is the problem


RE: why models are not loading in autoload - Wouter60 - 12-14-2019

Make sure your models are in the application/models folder and start with a capital letter.
When loading a model with $this->load->model( ... ) don't use a capital letter.
So, it's perfectly ok to load the Vacancy_model.php with $this->load->model('vacancy_model');
To refer to methods (functions) inside the model: $this->vacancy_model->function_name();