Welcome Guest, Not a member yet? Register   Sign In
Abour the URL
#1

[eluser]BobyKurniawan[/eluser]
Hi, it's me again, now i want to ask about the url (I dont how to name it). I try to create my own CMS.


First, i already make a article just for a test, this how to see the list of my article via url bar

Code:
http://localhost/framecode/admin/artikel


admin controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {
function artikel($offset=0)
{
$cek = $this->fc_model->cekaman();
if($cek!=null)
  {

$x = $this->input->post('cari');
$field= array('judul'=> $x);
    $data['include'] =  'admin/list_artikel';
  $this->db->where('flag',1);
    $this->db->like($field, $x);
    $jml = $this->db->get('artikel');
  $config['base_url'] = base_url().'admin/artikel';
  $config['total_rows'] = $jml->num_rows();
$config['per_page'] = 5;
$config['first_page'] = 'Awal';
$config['last_page'] = 'Akhir';
  $config['next_page'] = '«';
  $config['prev_page'] = '»';
  $this->pagination->initialize($config);
  $data['halaman'] = $this->pagination->create_links();
  $tbl='artikel';
  $data['artikel'] = $this->fc_model->tampildata2($config['per_page'], $offset,$tbl,$x,$field);




$this->load->view('admin/page',$data);
    }
   else
  {
       redirect('login','refresh');
  }
}

}


Then the lists of my articles will show up, now i want to see the article so i make a other controller like this ->
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class View extends CI_Controller {
function artikelview($id)
{
          $sql   = "select * from artikel where slug='$id'";
   $data['artikel'] = $this->fc_model->tampildata($sql);
   $this->load->view('home',$data);
}

}


this is the link from my view
Code:
<td class="action" ><a class="view">slug;?&gt;">View</a><a class="edit">idartikel;?&gt;">Edit</a> <a class="delete">idartikel;?&gt;">Delete </a></td>

well it's work when i click 'view' from the link. Then my url bar change to this

Code:
http://localhost/framecode/view/artikel/tes-new-cat

The problem is, if i chaenge 'tes-new-cat' to -> 'sdasad', this message is show up Message: Trying to get property of non-object

sorry for very bad english


#2

[eluser]CroNiX[/eluser]
I don't know why it works using
Code:
http://localhost/framecode/view/artikel/tes-new-cat

because in your View controller, the method name is artikelview, not "artikel", so the link should be
Code:
http://localhost/framecode/view/artikelview/tes-new-cat
and
Code:
http://localhost/framecode/view/artikelview/sdasad
#3

[eluser]BobyKurniawan[/eluser]
sorry, i copy wrong source code.

Everythings work know. i add this to my view

Code:
if(count($artikel)): foreach($artikelas $baris):

and blablalba

&lt;?php endforeach; ?&gt;
&lt;?php else: ?&gt;
Error message
&lt;?php endif; ?&gt;

Can i do that wat?




Theme © iAndrew 2016 - Forum software by © MyBB