Welcome Guest, Not a member yet? Register   Sign In
Records and array in the view
#1

[eluser]henry178[/eluser]
Hi,
i have this Model:


class Pagination1_model extends CI_Model
{
function __construct()
{
parent::__construct();
}


public function getAll_cabina($num, $offset) {
$data = $this->db->get('tab_anagrafica', $num, $offset);

if($data->num_rows()>0){
return $data->result_array();
}
else{
return false;
}
$data->free_result();

}
}

The control is this:

$this->load->model('pagination1_model');

$data['rows'] = $this->pagination1_model->getAll_cabina($config['per_page'], $this->uri->segment(2));

$this->load->view('template1/prova',$data);


In the view.... how do I see on the array?
#2

[eluser]InsiteFX[/eluser]
Code:
public function getAll_cabina($num, $offset)
{
    $data = $this->db->get(‘tab_anagrafica’, $num, $offset);

    if ($data->num_rows() > 0)
    {
        return $data->result_array();
    }
    else
    {        
        return false;
    }          

    // this is wrong, you will never get to here! should be removed!
    $data->free_result();
}

Your view code would be something like this, hard to tell without knowing your fields in the table!
Code:
<?php foreach($row as $rows):?>

<h2>&lt;?php echo $rows['field1'];?&gt;</h2>

<p>&lt;?php echo $rows['field2'];?&gt;</p>

&lt;?php endforeach;?&gt;

InsiteFX
#3

[eluser]henry178[/eluser]
[quote author="InsiteFX" date="1301514980"]
Code:
public function getAll_cabina($num, $offset)
{
    $data = $this->db->get(‘tab_anagrafica’, $num, $offset);

    if ($data->num_rows() > 0)
    {
        return $data->result_array();
    }
    else
    {        
        return false;
    }          

    // this is wrong, you will never get to here! should be removed!
    $data->free_result();
}

Your view code would be something like this, hard to tell without knowing your fields in the table!
Code:
&lt;?php foreach($row as $rows):?&gt;

<h2>&lt;?php echo $rows['field1'];?&gt;</h2>

<p>&lt;?php echo $rows['field2'];?&gt;</p>

&lt;?php endforeach;?&gt;

InsiteFX[/quote]


Perfect! :-)
#4

[eluser]henry178[/eluser]
in my routes.php:

$route['en'] = "home/en";
$route['en/beb'] = "home/en/";


my controller:

function en()
{
$this->load->library('pagination');

$config['first_link'] = 'Primo';
$config['next_link'] = 'avanti';
$config['prev_link'] = 'indietro';
$config['last_link'] = 'Ultimo';



$config['base_url'] = '/en';
$config['total_rows'] = $this->db->count_all('tab_anagrafica');
$config['per_page'] = '10';
$config['full_tag_open'] = '<div id="pagination">Pagine: ';
$config['full_tag_close'] = '</div>';

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


$this->load->model('pagination1_model');

$data['rows'] = $this->pagination1_model->getAll_cabina($config['per_page'], $this->uri->segment(1));

$this->load->view('template1/prova',$data);
}


in my view:

&lt;?php echo $this->pagination->create_links(); ?&gt;
<record>
&lt;?php echo $this->pagination->create_links(); ?&gt;

but if i click in the pagination i receive this url: http://localhost/en&per_page=10

ERROR 404
I was expecting: http://localhost/en?per_page=10


why there isn't question mark in the url?

and why the records do not flow?
#5

[eluser]InsiteFX[/eluser]
You must have this set in your application/config/config.php
Code:
$config['page_query_string'] = TRUE;

InsiteFX
#6

[eluser]henry178[/eluser]
[quote author="InsiteFX" date="1301525094"]You must have this set in your application/config/config.php
Code:
$config['page_query_string'] = TRUE;

InsiteFX[/quote]

never change! The url is the same: http://localhost/en&per_page=10

404 Page Not Found


why this error? Sad
#7

[eluser]henry178[/eluser]
in the Model:

public function getAll_cabina($num, $offset) {

echo "num: ";
echo $num;

echo "<br>offset: ";
echo $offset;
echo "<br>";


$data = $this->db->get('tab_anagrafica', $num, $offset);

if($data->num_rows()>0){
return $data->result_array();
}
else{
return false;
}
$data->free_result();

}


var offset is ever empty....
#8

[eluser]InsiteFX[/eluser]
From the looks of it, it looks like your language is adding the & or your routes.php
what is this set to in application/config/config.php ?
Code:
$config['uri_protocol']    = 'AUTO';

InsiteFX
#9

[eluser]henry178[/eluser]
[quote author="InsiteFX" date="1301594927"]From the looks of it, it looks like your language is adding the & or your routes.php
what is this set to in application/config/config.php ?
Code:
$config['uri_protocol']    = 'AUTO';

InsiteFX[/quote]

this is my:

$config['uri_protocol'] = 'AUTO';

the same.... Sad


My routes:

$route['default_controller'] = "home/en";
$route['404_override'] = '';


// URI like '/en/about' -> use controller 'about'
//$route['^fr/(.+)$'] = "$1";
//$route['^en/(.+)$'] = "$1";

// '/en' and '/fr' URIs -> use default controller
//$route['^fr$'] = $route['default_controller'];
//$route['^en$'] = $route['default_controller'];

$route['en'] = "home/en";
$route['en/agriturismi'] = "home/en/";
$route['en/agriturismi/([a-z]+)'] = "home/en/$1";
#10

[eluser]henry178[/eluser]
if change this:

$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;

this is the result url
http://localhost/en/10

404 Page Not Found :-(




Theme © iAndrew 2016 - Forum software by © MyBB