Welcome Guest, Not a member yet? Register   Sign In
Do I need to upgrade my version of CodeIgniter?
#21

[eluser]Bob Puzld[/eluser]
Sorry for my ignorance... controller method? model method(in code tags)?

Not sure why we are not getting any results either. Nothing has changed on our end since the server upgrades. Just the output.

Yes, it is a typo. It should have read 'payouts'


Thanks for your persistent help BTW!
#22

[eluser]Bob Puzld[/eluser]
Did I scare you away with my ignorance? Smile
#23

[eluser]TheFuzzy0ne[/eluser]
No not at all. It's just that 4 year old boys can be distracting. I totally forgot to reply. Sorry about that.

We could really do with seeing your code to try and figure out why you aren't getting a result. If the table contains data (which it does), then so should the result array. I'd like to see (by the code for your controller method) how you're calling your model, and what's in your model (by the code for your model method). I'm suspecting that there's a fault in the syntax somewhere.
#24

[eluser]Bob Puzld[/eluser]
Are you talking about the code from the php files that are in the controllers and models folders within /system/application/ ??
#25

[eluser]TheFuzzy0ne[/eluser]
Yes. Smile
#26

[eluser]Bob Puzld[/eluser]
First controller file... collections.php

<?php

class Collections extends Controller {
function Collections() {
parent::Controller();

$this->load->model('collection_model','mdlCollection');

$this->load->library('auth',array('redirect'=>'main','hash_key'=>$this->config->item('hash_key')));
}

function index() {
$data = array('page_title'=>'Manage Collections',
'left_col'=>$this->load->view('nav',0,true),
'right_col'=>$this->load->view('collections/add',0,true));

$this->load->view('index', $data);
}

function UserCheck($anID) {
$this->db->where('id',$anID);
$query = $this->db->get('users');

if($query->num_rows() == 0) {
$this->validation->set_message('UserCheck','That account number doesnt exist. Please try a different one.');
return FALSE;
}
else
return TRUE;
}

function NumCansCheck($aNum) {
if($aNum >= 1000) {
$this->validation->set_message('NumCansCheck','Number of cans must be less than 1000.');
return FALSE;
}
else
return true;
}

function add_collection() {
// validate input
$rules = array('user_id'=>'required|numeric|callback_UserCheck',
'num_cans'=>'required|numeric|callback_NumCansCheck',
'date'=>'required');

$fields = array('user_id'=>'account number',
'num_cans'=>'number of cans collected');

$this->validation->set_rules($rules);
$this->validation->set_fields($fields);

// check for errors
if($this->validation->run() == FALSE) { // if there were errors...
$this->index();
}
else {
$this->mdlCollection->AddCollection();
redirect('collections/index');
}
}
}

?>
#27

[eluser]Bob Puzld[/eluser]
Next controller file... districts.php

<?php

class Districts extends Controller {
function Districts() {
parent::Controller();

$this->load->model('district_model','mdlDistrict');

$this->load->library('auth',array('redirect'=>'main','hash_key'=>$this->config->item('hash_key')));
}

function index() {
$data2['districts'] = $this->mdlDistrict->GetAll();

$data = array('page_title'=>'Manage Districts',
'left_col'=>$this->load->view('nav',0,true),
'right_col'=>$this->load->view('districts/index',$data2,true));

$this->load->view('index', $data);
}

function add() {
// validate input
$rules = array('name'=>'required');

$this->validation->set_rules($rules);

// check for errors
if($this->validation->run() == FALSE) { // if there were errors...
$this->index();
}
else {
$this->mdlDistrict->AddDistrict();
redirect('districts/index');
}
}
}

?>
#28

[eluser]Bob Puzld[/eluser]
Next controller file… login.php

<?php

class Login extends Controller {
function Login() {
parent::Controller();
}

function log_in() {
$this->load->library('auth',array('redirect'=>'main','hash_key'=>$this->config->item('hash_key')));

switch($this->session->userdata('ROLE')) {
case 1:
$this->db->select('name');
$this->db->from('districts');
$this->db->join('users','users.district_id = districts.id','INNER');
$this->db->where('users.id',$this->session->userdata('USER_ID'));
$query = $this->db->get();
$user = $query->row();

$this->session->set_userdata(array('DISTRICT'=>$user->name));

redirect('main/account_status');
break;

case 2:
redirect('');
break;

case 3:
redirect('users/index');
break;
}
}

function logout() {
$this->load->library('auth',array('redirect'=>'main','hash_key'=>$this->config->item('hash_key')));
$this->auth->Logout();
}
}

?>
#29

[eluser]Bob Puzld[/eluser]
Next controller file… main.php

<?php

class Main extends Controller {
function Main() {
parent::Controller();

$this->load->model('district_model','mdlDistrict');
$this->load->model('user_model','mdlUser');
}

function index() {
$data = array('page_title'=>'Returnable Redemption Reward Program',
'left_col'=>$this->load->view('main/login',0,true),
'right_col'=>$this->load->view('main/index',0,true));

$this->load->view('index', $data);
}

function signup() {
$query = $this->mdlDistrict->GetAll();
foreach($query->result() as $row)
$districts[$row->id] = $row->name;

$data2['districts'] = $districts;

$data = array('page_title'=>'RRR Sign-Up',
'left_col'=>$this->load->view('main/signup_sidebar',0,true),
'right_col'=>$this->load->view('main/signup',$data2,true));

$this->load->view('index', $data);
}

function signup_process() {
// validate input
$rules = array('district_id'=>'required',
'fname'=>'required|alpha',
'lname'=>'required|alpha',
'street'=>'required|numeric',
'address'=>'required',
'city'=>'required',
'zip'=>'required|numeric',
'email'=>'required|valid_email',
'username'=>'required',
'password'=>'required');

$fields = array('district_id'=>'school district',
'fname'=>'first name',
'lname'=>'last name',
'email'=>'e-mail address');

$this->validation->set_rules($rules);
$this->validation->set_fields($fields);

// check for errors
if($this->validation->run() == FALSE) { // if there were errors...
$this->signup();
}
else {
$this->mdlUser->AddUser();

$this->load->library('email');

$this->email->from('[email protected]','RRR Program');
$this->email->to($_POST['email'],$_POST['fname'].' '.$_POST['lname']);

$this->email->subject('Welcome to the RRR Program');
$this->email->message("Thank you for signing-up for the RRR Program. You will receive your pick-up day in another e-mail shortly.\n\nRRR Program");
$this->email->send();

redirect('main/index');
}
}

function account_status() {
$data2 = $this->mdlUser->GetAccountStatus($this->session->userdata('USER_ID'));

$data = array('page_title'=>'Account Status',
'left_col'=>$this->load->view('nav',$data2,true),
'right_col'=>$this->load->view('users/view',$data2,true));

$this->load->view('index', $data);
}

function test() {
echo mktime(12,0,0,5,9,2006);
}
}

?>
#30

[eluser]TheFuzzy0ne[/eluser]
Please could you put [code][/code] tags around your code.

[code]
# your code here
[/code]

It makes it a lot easier to read. Smile




Theme © iAndrew 2016 - Forum software by © MyBB