Welcome Guest, Not a member yet? Register   Sign In
Secondary Controller doesn't load view
#1

[eluser]teomatteo89[/eluser]
Hi,
I'm using CI form just a couple of week, so i'm practically a newbie of this framework.

I'm having issues with my secondary controller or the routes.php configuration file - i think -, and i can't understand why.

This is my routes.php:
Code:
$route['default_controller'] = '/view';

//show customers
$route['] = '/index';

//Registration
$route['registrazione'] = 'form';
$route['form'] = 'form';

$route['(:any)'] = '/view/$1';

Basically, I'm writing a simple e-commerce site.
By now, i have the main view of the site loaded from the basicViewController file. The view loaded has at the top a menu with 4 links to 4 different pages, and one of them is "controlled" from another controller file, userlist.php.

Userlist.php:
Code:
<?php

// Controller per la visu degli utenti registrati al sito web
class Userlist extends CI_Controller{
  
public function __construct()
{
  parent::__construct();
  $this->load->model('modelpizzeria');
  $this->output->enable_profiler(TRUE);
}
  
public function index()
{
  $data['users'] = $this->modelpizzeria->get_user();

//  $data['title'] = "Visualizza Utenti";
  
  $title = "Visualizza";
  
  $this->load->view('templates/header', $title);
  $this->load->view('templates/menu');
  $this->load->view('pagine/clienti', $data);
  $this->load->view('templates/footer');
}
}

How you can see, there's also a model connected to a database: i'm trying to print every user saved.

modelpizzeria.php:
Code:
<?php

class Modelpizzeria extends CI_Model {

public function __construct()
{
  parent::__construct();
  $this->load->database();
}

public function get_user()
{
  $query = $this->db->get(');
  return $query->result();
}

}

And this is how i should view all my users:

Code:
/*
  $this->load->view('templates/header', $title);
*/
<!--Header file -->
<html>
<head>
<style type="text/css">
//Some CSS style here
</style>
<title>Pizzeria PEM - <?php echo $title?></title>
</head>

<body class="body">
<h1 id="title">Pizzeria PEM</h1>

/*
  $this->load->view('templates/menu');
*/

&lt;!-- Tabella menu --&gt;
<table id="menu" cellspacing="20px" cellpadding="10px">
  <tr>
   <td>&lt;?php echo anchor('home', 'Menu');?&gt;    </td>
   <td>&lt;?php echo anchor('ordinazioni', 'Ordinazioni');?&gt; </td>
   <td>&lt;?php echo anchor('clienti', 'Lista utenti');?&gt;  </td>
   <td>&lt;?php echo anchor('about', 'About Pizzeria');?&gt;  </td>
  </tr>
</table>

/*
  $this->load->view('pagine/clienti', $data);
*/

&lt;!-- Visualizzazione degli utenti contenuti nel database. --&gt;
<h1> Lista Clienti </h1>

&lt;?php foreach($users as $customer): ?&gt;

<h2>Nome Utente: &lt;?php echo $customer->Login; ?&gt;</h2>
<h4>Password:   &lt;?php echo $customer->Password; ?&gt; </h4>
<h6>ID:    &lt;?php echo $customer->CodCliente; ?&gt; </h6>

&lt;?php endforeach ?&gt;

/*
  $this->load->view('templates/footer');
*/
&lt;!-- Footer File --&gt;
&lt;/body&gt;
&lt;/html&gt;

But, when write localhost:8888/Pizzeria/index.php/userlist/index or when i click the link anchored(in menu.php), the page doesn't load anything. It simply stays all white. Can someone help me to figure out what's happening?

Thank you and sorry for my "not so correct" English.
#2

[eluser]DarkManX[/eluser]
You need to set routing to the userlist or just take out the bottom rule of routing.

Code:
$route['(:any)'] = '/view/$1';

normally you would need to /userlist/index to get to the index-method of userlist but your last rule sends everything but /registrazione and /form to the view controller. so if you would call /userlist/index now you will be routed to /view/userlist/index - to the userlist-method of the view-controller (if you are using standard dir-structure).
#3

[eluser]teomatteo89[/eluser]
Thanks for the reply.
Unfortunately, my first post omitted part of the configuration file.

Here is the routes.php:
Code:
$route['default_controller'] = 'basicViewController/view';

$route['clienti'] = 'userlist/index';

$route['registrazione'] = 'form';
$route['form'] = 'form';

$route['(:any)'] = 'basicViewController/view/$1';

If i understood correctly how routing works, when the page "clienti" is requested, codeigniter redirect the request to the controller userlist(saved into application/controllers/) and asking for method index... But i don't see anything displayed at link "http://localhost:8888/Pizzeria/index.php/clienti".
If i comment the line
Code:
$route['clienti'] = 'userlist/index';
, the site displays the view, but with the wrong controller.
(This is what i see when i comment the line: https://dl.dropbox.com/u/411738/screenshot1.png)
#4

[eluser]InsiteFX[/eluser]
You donot need to add the index, index is the controllers default method.
Code:
$route['clienti'] = 'userlist';
#5

[eluser]DarkManX[/eluser]
which controller you was led to by calling /clienti.

a small hint: dont mix languages, just use english.
#6

[eluser]teomatteo89[/eluser]
Following your advice, i just translated everything to english.
(By the way, my code is hosted here: https://github.com/teomatteo89/ProgettoDatabase)

about
Code:
$route['customers'] = 'userlist';
I've removed "index".

I double checked everything, but i really don't understand why that page is completely white.




Theme © iAndrew 2016 - Forum software by © MyBB