CodeIgniter Forums
method in a controller calling another method..... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: method in a controller calling another method..... (/showthread.php?tid=42978)



method in a controller calling another method..... - El Forum - 06-25-2011

[eluser]Salman Khimani[/eluser]
class Categories extends CI_Controller {


public function __construct() {
parent::__construct();
//load libraries to use
$this->load->library('session');
$this->load->model('adminManager');
$this->load->model('categoryManager');
$this->load->helper('url');
}

public $data = array(
'errorMsg' => '',
'successMsg' => '',
'singularTitle' => 'Category',
'pluralTitle' => 'Categories',
'pageAction' => 'Listing',
'directory' => 'categories'
);


public function index()
{
$this->adminManager->checkAdminAuth();

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

$order = $this->uri->segment(4, 'id');
$direction = $this->uri->segment(5, 'DESC');
$offset = $this->uri->segment(6, 0);
$perpage = 10;

$config['base_url'] = base_admin_url() . 'categories/index/'. $order .'/'. $direction .'/';
$config['total_rows'] = $this->categoryManager->findAllIds(array('count' => true));
$config['per_page'] = $perpage;
$config['uri_segment'] = 6;
$config['first_link'] = '';
$config['prev_link'] = '';
$config['next_link'] = '';
$config['last_link'] = '';
$config['first_anchor_class'] = 'page-far-left';
$config['prev_anchor_class'] = 'page-left';
$config['next_anchor_class'] = 'page-right';
$config['last_anchor_class'] = 'page-far-right';
$config['num_tag_open'] = '<div id="page-info">';
$config['num_tag_close'] = '</div>';
$config['cur_tag_open'] = '<div id="page-info">';
$config['cur_tag_close'] = '</div>';
$config['ajax_paging'] = TRUE;
$config['ajax_div'] = 'content';
$config['ajax_spinner'] = 'spinner';

$this->pagination->initialize($config);

$this->data['offset'] = $offset;
$this->data['pagination'] = $this->pagination->create_links();
$options = array(
'limit' => $perpage,
'offset' => $offset,
'order' => $order,
'direction' => $direction
);
$userIdsData = $this->categoryManager->findAllIds($options);

$this->data['finalData'] = array();
foreach($userIdsData as $userIdData) {
$this->data['finalData'][] = $this->categoryManager->findById($userIdData->user_id);
}

if($this->input->is_ajax_request() != 1) { $this->load->view('administrator/header'); }
$this->load->view('administrator/'.$this->data['directory'].'/index',$this->data);
if($this->input->is_ajax_request() != 1) { $this->load->view('administrator/footer'); }
}

public function add()
{
$this->adminManager->checkAdminAuth();
$this->data['pageAction'] = 'add';

if($this->input->post('doAct')==strtolower($this->data['pageAction'])) {
if($this->input->post('name')=='') {
$this->data['errorMsg'] = 'Please enter '.$this->data['singularTitle'].' name.';
//error is saved to be displayed. now continue to add page
}
else {
//enter data to db and show index with success message
$this->data['successMsg'] = 'Thanks......';
$this->index(); exit; //Why this shows blank page? It should continue to 'index' method.
}
}
if($this->input->is_ajax_request() != 1) { $this->load->view('administrator/header'); }
$this->load->view('administrator/'.$this->data['directory'].'/add',$this->data);
if($this->input->is_ajax_request() != 1) { $this->load->view('administrator/footer'); }
}

}








I am stuck here...... cannot go ahead.


method in a controller calling another method..... - El Forum - 06-25-2011

[eluser]bgreene[/eluser]
I remember having the same problem long time back with ci17 and if i recall correctly, it was caused by having public in front of the functions. not familiar enough with php to understand why so i just accepted it and now my functions dont have public in front


method in a controller calling another method..... - El Forum - 06-25-2011

[eluser]Salman Khimani[/eluser]
no.... its not working even when i remove public.
This is something else because all functions in a class that we create are usually public (even if we don't declare function as public in front of them). private and protected needs to be written as private/protected.
M stuck with my project because of this. Cannot finish with delete/update/edit until this is resolved.


method in a controller calling another method..... - El Forum - 06-25-2011

[eluser]Salman Khimani[/eluser]
Got it....
Oh Google, I would have committed suicide if u weren't here for us ... Smile
Many thanks to Phil Sturgeon :
on : http://stackoverflow.com/questions/2618993/php-codeigniter-use-of-exit
for words :
Generally speaking though, if you use exit() it will stop the Output library for running. If you just want to stop the current controller from executing but allow output of the controller you can use return in exactly the same way.

Concluded : Its not a bug by codeigniter.
Loving it.....


method in a controller calling another method..... - El Forum - 06-27-2011

[eluser]Unknown[/eluser]
Yes, I too was a problem.