[eluser]NyiPHP[/eluser]
I have been looking at
http://ellislab.com/codeigniter/user-gui...arser.html
http://williamsconcepts.com/ci/codeignit...rence.html
Currently (without using the config/template.php functionality) i load all the views (header/sidebar/contetent/footer)
We can take a look on my article-setup.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Artikkel extends CI_Controller {
public function __construct() {
parent:: __construct();
$this->load->model("model_artikkel");
$this->load->library("pagination");
}
public function index() {
$this->alle();
}
public function alle() { // shows all articles, with a pagination
$config = array();
$config["base_url"] = base_url()."artikkel/alle";
$config["total_rows"] = $this->model_artikkel->antall_artikler();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->model_artikkel->hentArtikler($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("des_header");
$this->load->view("des_sidebarmain");
$this->load->view("des_sidebarend");
$this->load->view("con_artikkel", $data);
$this->load->view("des_footer");
}
public function vis() { // shows 1 specific article
$alias = $this->uri->segment(3);
$this->load->view("des_header");
$this->load->view("des_sidebarmain");
$this->load->view("des_sidebarend");
$data['resultater'] = $this->model_artikkel->visEn($alias);
$this->load->view("con_artikkel_en",$data);
$this->load->view("des_footer");
}
}
here i load each view on each function. i think the template-library would help me out here, with not having to do this all the time, and manually.
and the con_artikkel view looks this way.
Code:
<?php
foreach($results as $data){
echo '
<div class="content">
<h1>'.$data->tittel.'</h1>
<div class="content_item">
<p>'.$data->ingress.'</p>
<p>Skrevet '.$data->skrevet.' - <a href="'.base_url().'artikkel/vis/'.$data->alias.'">Les mer</a></p>
</div>
</div>';
}
echo '
<div class="content">
<div class="content_item">
<p>'.$links.'</p>
</div>
</div>';
?>
i have got an "overall-understanding", but somehow i dont get how to impliment this to my site.
EDIT:
And if needed, this is my article-model.
Code:
<?php
class Model_artikkel extends CI_Model{
public function __construct() {
parent::__construct();
}
public function antall_artikler() { // c. all articles.
return $this->db->count_all("xxx");
}
public function hentArtikler($limit, $start) { //get all, and paginate them
$this->db->limit($limit, $start * $limit);
$query = $this->db->get("xxx");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
function visEn($alias) { //show one
$query = $this->db->query("SELECT xxx FROM xxx WHERE xxx='$alias' LIMIT 1");
return $query->result();
}
}
?>