Welcome Guest, Not a member yet? Register   Sign In
controller/view/view
#1

[eluser]ZioN[/eluser]
Hi there,

Recently started with CodeIgniter and I like it. I am building myself a website but I have this issue and cannot find out how I should do it.

This is the situation:
I have an admin panel and a 'user' view. The url is looking like this: acp/users where acp is the controller and users is the view. On the users page I have a button with Add User, and I want this to point to acp/users/add_user.

What's the best method of doing this?

~ Nick
#2

[eluser]noideawhattotypehere[/eluser]
Code:
anchor('controller/method', 'Add User', array(class="your-button-class"));

in your controller
public function method() {
$this->load->view('whateverviewfileyouwantwithoutextension');
}

#3

[eluser]ZioN[/eluser]
Perhaps I did not explain my question thoroughly.

My setup:
acp/users

acp is the controller and users is the view. The users view is a default page with some general information. On that page I have a little menu with "Add user". I want this to point to acp/users/add_user and I want that page to display my form.

How do I add that last part (add-user)? I tried several options (routes etc.) but I have not found a way to make that work yet.
#4

[eluser]noideawhattotypehere[/eluser]
I kinda dont understand your app build. How do you call controller/view directly? Its controller/method, and method can load diffrent views. Maybe you should post your acp controller code. Im either tired or just simply we dont understand each other :p
#5

[eluser]ZioN[/eluser]
I meant method indeed. My bad.

Code:
class Acp extends CI_Controller {
// Load login page as default (index)
public function index(){
  $this->login();
}
// The actual admin panel
public function dashboard(){
if ($this->session->userdata('is_logged_in')){ // if logged in, proceed
  $this->load->view('acp/includes/head.php');
  $this->load->view('acp/dashboard_view');
  $this->load->view('acp/includes/footer.php');
  }
  else{
   redirect('acp/login');
  }
}
public function users(){
if ($this->session->userdata('is_logged_in')){ // if logged in, proceed
  $this->load->view('acp/includes/head.php');
  $this->load->view('acp/users_view');
  $this->load->view('acp/includes/footer.php');
  }
  else{
   redirect('acp/login');
  }
}

After acp/users I want add_user which displays a form to add a user.
#6

[eluser]noideawhattotypehere[/eluser]
Controller:
Code:
public function add_user(){
if ($this->session->userdata('is_logged_in')){
  $this->load->view('acp/includes/head');
  $this->load->view('acp/add_user_view');
  $this->load->view('acp/includes/footer');
  }
  else{
   redirect('acp/login');
  }
config/Routers.php:
$route['acp/users/add_user'] = "acp/add_user";

Then you should be able to point to domain.com/acp/users/add_user and see your form. (located in views/acp/add_user_view.php)
#7

[eluser]ZioN[/eluser]
Perfect! Thanks a bunch.




Theme © iAndrew 2016 - Forum software by © MyBB