[eluser]Unknown[/eluser]
UPDATE: now the page seems to be working.
BUT not the URL. point is that having 25 tot rows in a table, last page will be page/pag/24 instead page/pag/25 because the first page is page/pag/0
I need to show one result per page,that's it.
Thanks for any help. (?)
Code:
autoload.php
$autoload['libraries'] = array('database', 'session', 'pagination','xmlrpc');
$autoload['helper'] = array('file', 'url', 'recaptcha', 'template_inheritance');
Code:
routes.php
$route['default_controller'] = "page/pag";
in config.php I get
$config['index_page'] = "";
UPDATE:it was mostly an htaccess issue
Code:
htaccess:
RewriteEngine On
RewriteBase /vinyl
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
[code]model: conf.php
<?php
class Conf extends Model {
function conf()
{
// Call the Model constructor
parent::Model();
}
function tot()
{
$q = $this->db->get('canzoni');
return $q->result();
}
function one()
{
$one = $this->db->get('canzoni', 1);
return $one->result();
}
// get records from database
function get($offset = NULL, $num_per_page = NULL)
{
$this->db->from('canzoni');
if (isset($offset) && isset($num_per_page)) {
$this->db->limit($num_per_page, $offset);
}
return $this->db->get()->result();
}
function row_count()
{
return $this->db->count_all('canzoni');
}
function ua(){
if ($this->agent->is_browser())
{
$agent = $this->agent->browser().' '.$this->agent->version();
}
elseif ($this->agent->is_robot())
{
$agent = $this->agent->robot();
}
elseif ($this->agent->is_mobile())
{
$agent = $this->agent->mobile();
}
else
{
$agent = 'Unidentified User Agent';
}
echo $agent;
}
// end class
}
?>
Code:
controller: page.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Page extends Controller {
function Page(){
parent::Controller();
}
function index()
{
$this->pag();
}
function pag($offset = 0, $page = 'home')
{
$this->load->model('conf');
$data = array();
$data['titolo'] = 'Discografia vinile';
$data['si'] = $session_id = $this->session->userdata('session_id');
$data['info'] = $this->benchmark->elapsed_time();
// Pagination
$num_per_page = 1;
$tot_rows = $this->conf->row_count();
$config['base_url'] = site_url('page/pag/');
$config['total_rows'] = $tot_rows;
$config['per_page'] = $num_per_page;
$config['first_link'] = 'Prima pagina';
$config['first_tag_open'] = '<li>';
$config['last_link'] = 'Ultima pagina';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next >';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '< Back';
$config['prev_tag_open'] = '<li>';
$config['full_tag_open'] = '<ul class="navrecords">';
$config['full_tag_close'] = '</ul>';
$config['cur_tag_open'] = '<li>';
$config['cur_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('canzoni',$num_per_page,$offset)->result();
print 'offset:'. $offset;
$this->load->view('pages/'.$page, $data);
}
}
?>
Code:
view: views/pages/home.php
<?php extend('master_template.php');
startblock('listapag');
echo $this->pagination->create_links();
print '<p>last query:'.$this->db->last_query().'</p>'; ?>
<dl>
<?php foreach($records as $row) { ?>
<dt><?php echo $row->autore; ?></dt>
<dd><?php echo $row->titolo; ?>
<ul>
<li><?php echo $row->anno; ?></li>
<li><?php echo $row->Label; ?></li>
<li>ID: <?php echo $row->id; ?></li>
</ul>
</dd>
<?php }; ?>
</dl>
<?php //echo $this->pagination->create_links(); ?>
<p class="data">Totale titoli presenti: <strong><?php echo $this->conf->row_count(); ?></strong></p>
<p>Page generated in <strong><?php print $info; ?></strong></p>
<?php endblock();
end_extend(); ?>