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

[eluser]sb05[/eluser]
Hi all,

been strugling with this quit some time now, hope that someone can help me.

I got a menu with several items, like: news, interviews, events etc.

When i go to www.domain.com/interviews/view/2 it displays a interview, but when i want to go to events the url becomes: www.domain.com/interviews/view/events and but it should be www.domain.com/events.
So the correct page doesn't load.

What am i doing wrong here or is this something with codeigniter?

I'm using codeigniter 1.7.3.

Thanks in advance,

Sean
#2

[eluser]mi6crazyheart[/eluser]
Can u show us u'r controller's code... ?
#3

[eluser]sb05[/eluser]
<?php
class Events extends Controller {

// num of records per page
private $limit = 10;

function Events(){
parent::Controller();

// load library
$this->load->library(array('table','validation'));

// load helper
$this->load->helper('url');

// load model
$this->load->model('eventModel','',TRUE);
}

function index($offset = 0){
// offset
$uri_segment = 3;
$offset = $this->uri->segment($uri_segment);

// load data
$events = $this->eventModel->get_paged_list($this->limit, $offset)->result();

// generate pagination
$this->load->library('pagination');
$config['base_url'] = site_url('events');
$config['total_rows'] = $this->eventModel->count_all();
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();

// generate table data
$this->load->library('table');
$this->table->set_empty(" ");
$this->table->set_heading('No', 'Name', 'Date', 'Location','City', 'Link', 'Actions');
$i = 0 + $offset;
foreach ($events as $event){
$this->table->add_row(++$i, $event->name, date('d-m-Y',strtotime($event->date)), $event->location, $event->city, $event->link,
anchor('events/view/'.$event->event_id,'view',array('class'=>'view')).' '.
anchor('events/update/'.$event->event_id,'update',array('class'=>'update')).' '.
anchor('events/delete/'.$event->event_id,'delete',array('class'=>'delete','onclick'=>"return confirm('Are you sure want to delete this event?')"))
);
}
$data['table'] = $this->table->generate();

// load view
$this->load->view('banner_view', $data);
$this->load->view('left_column_view', $data);
$this->load->view('right_column_view', $data);
$this->load->view('eventList', $data);
$this->load->view('footer_view', $data);

}

function add(){
// set validation properties
$this->_set_fields();

// set common properties
$data['title'] = 'Add new event';
$data['message'] = 'COMMON PROPERTIESSS';
$data['action'] = site_url('events/addEvent');
$data['link_back'] = anchor('events','Back to list of events',array('class'=>'back'));

// load view
$this->load->view('banner_view', $data);
$this->load->view('left_column_view', $data);
$this->load->view('right_column_view', $data);
$this->load->view('eventEdit', $data);
$this->load->view('footer_view', $data);
}

function addEvent(){
// set common properties
$data['title'] = 'Add new event';
$data['action'] = site_url('events/addEvent');
$data['link_back'] = anchor('events','Back to list of events',array('class'=>'back'));

// set validation properties
$this->_set_fields();
$this->_set_rules();

// run validation
if ($this->validation->run() == FALSE){
$data['message'] = 'Validatie is FOUTTT';
}else{
// save data
$event = array('name' => $this->input->post('name'),
'date' => date('Y-m-d', strtotime($this->input->post('date'))),
'location' => $this->input->post('location'),
'city' => $this->input->post('city'),
'link' => $this->input->post('link'));

$event_id = $this->eventModel->save($event);

// set form input name="id"
$this->validation->name = $event_id;

// set user message
$data['message'] = '<div class="success">add new event success</div>';
}

// load view
$this->load->view('banner_view', $data);
$this->load->view('left_column_view', $data);
$this->load->view('right_column_view', $data);
$this->load->view('eventEdit', $data);
$this->load->view('footer_view', $data);
}

function view($event_id){
// set common properties
$data['title'] = 'event Details';
$data['link_back'] = anchor('events','Back to list of events',array('class'=>'back'));

// get event details
$data['events'] = $this->eventModel->get_by_id($event_id)->row();

// load view
$this->load->view('banner_view', $data);
$this->load->view('left_column_view', $data);
$this->load->view('right_column_view', $data);
$this->load->view('eventView', $data);
$this->load->view('footer_view', $data); }



Is this enough? Can post the other half if you want.

Thanks,
Sean
#4

[eluser]mi6crazyheart[/eluser]
If u want u'r url should be like this "www.domain.com/events" then u should've a controller by name "events". So, do u've any CONTROLLER by name "events"... ?
#5

[eluser]Rob @ iFetch[/eluser]
[quote author="mi6crazyheart" date="1292717402"]If u want u'r url should be like this "www.domain.com/events" then u should've a controller by name "events". So, do u've any CONTROLLER by name "events"... ?[/quote]

I might be missing something, but did (s)he not just post the events controller above?

To the OP: In your interviews/view view are you using absolute or relative URL's?

I.e. to link to www.domain.com/events, are you just using <a href="events">? If so, you'll need to use <a href="/events"> or the full URL.
#6

[eluser]mi6crazyheart[/eluser]
Oops, i think i'd lost mind on yesterday... Tongue. Thx @robfromnewy for informing

@sb05
Hey, use CI's anchor() to get anchor link in u'r "www.domain.com/interviews/view/" page. May be i think the needed code for the link should be like this. Try it...
Code:
echo anchor('events','EventPage'); // for this u'r base url should be "www.domain.com/".
#7

[eluser]sb05[/eluser]
Thanks for the quick posts. The problem was indeed the absolute url's. Had to adjust the path in the view en everything works nice now.

Thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB