Welcome Guest, Not a member yet? Register   Sign In
How does controller in CodeIgniter work? And what kind of variable can work during controller is called?
#1

[eluser]greedyman[/eluser]
The first thing I want to ask is how does controller work? Assuming that I have a controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

public static $groupId;

public function __construct() {
  
}

public function index() {
  $this->load->model('product_model');
  
  $data['new_products'] = $this->product_model->get_new_products();
  $data['featured_products'] = $this->product_model->get_featured_products();
  $data['sale_products'] = $this->product_model->get_sale_products();

  $data['template'] = 'index';
  $data['title'] = 'Home';
  
  $this->load->view('master', $data);
}

public function group($groupId) {
  $this->load->model('group_model');
  $this->load->model('product_model');
  
  $groupId = array_pop(explode('-', $groupId));
  self::$groupId = $groupId;
  
  $data['groupName'] = $this->group_model->get_group_name($groupId);
  $data['allGroupWithQuantity'] = $this->group_model->get_group_with_quantity();
  $data['products'] = $this->product_model->get_products_by_group($groupId);
  
  $data['template'] = 'group';
  $data['title'] = $data['groupName']->groupName;
  
  $this->load->view('master', $data);
}

public function test() {
  echo seft:$groupId;
}

}

/* End of file home.php */
/* Location: ./application/modules/front/controllers/home.php */

When I access http://localhost:8080/ci/ and http://localhost:8080/ci/television.html and then type http://localhost:8080/ci/test/, I get white screen. If in the first time controller is called (use method in controller), and in the second time, I think controller don't need reload so from group method, I set value for $groupId and in the test method I can get it easy but I can't. Maybe when I call test method, controller is reloaded.

The second thing I want to ask, how to pass $groupId through other method? Remember! $groupId doesn't store in controller, I get it from url.




Theme © iAndrew 2016 - Forum software by © MyBB