Welcome Guest, Not a member yet? Register   Sign In
Help with CI, PHP & Javscript
#21

[eluser]LuckyFella73[/eluser]
No problem - try this code to generate your link-list:
Code:
<div id="events">
&lt;?php
foreach( $events as $key => $value)
{
    echo "<h3>";
    echo anchor('events/getAll/'.$value);
    echo "</h3>";
}
?&gt;
</div>
</div>
&lt;!-- content left --&gt;
#22

[eluser]the_unforgiven[/eluser]
Sad another error

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: views/events.php

Line Number: 76

Appreciate your help so far, and looking at this you will be able to help me to get this to work Smile
#23

[eluser]the_unforgiven[/eluser]
I did manage to get it working like this:

Code:
&lt;?php foreach($events as $item) : ?&gt;
    <h3>&lt;?php echo anchor('events/getAll/'.$item->id, 'Date'); ?&gt;</h3>
&lt;?php endforeach; ?&gt;
But then when you navigate to the link it show 404 error.
#24

[eluser]the_unforgiven[/eluser]
and the anchor link is actuall getLeft as a pose to get getAll has per my controller & model:

Code:
Controller:

$data['events'] = $this->Eventsmodel->getLeft();

Code:
Model

function getLeft(){
       $query = $this->db->select('id', 'title', 'created_on');
       $query = $this->db->where('published', 'active');
       $query = $this->db->get('mcd_events');
       return $query->result();
    }
#25

[eluser]the_unforgiven[/eluser]
Any idea's???
#26

[eluser]LuckyFella73[/eluser]
Code:
&lt;?php echo anchor('events/getAll/'.$item->id, 'Date'); ?&gt;

# events/getAll
# => controller 'events'
# => Method/function 'getAll'

You don't have that method in your controller thats why you
get a 404 error.

You need to set up the method ( function getAll() {} ) and in that method you do the
call to your modell to get the informations you want to display.
#27

[eluser]the_unforgiven[/eluser]
I have this in my model:

Code:
function getLeft(){
       $query = $this->db->select('id', 'title', 'created_on');
       $query = $this->db->where('published', 'active');
       $query = $this->db->get('mcd_events');
       return $query->result();
    }
Or am i getting mixed up between the two, what should I have in the controller and model then? Just to point out if am on the right tracks.

Full Controller File
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Events extends Controller {
        
    function __construct() {
            parent::__construct();

            $this->load->helper('url');
            $this->load->model('Eventsmodel');
            $this->config->load('mcd');
    }

    function index() {
        
        // Get UL list for navigation
        $data['events'] = $this->Eventsmodel->getLeft();
        
        //$controller = $this->uri->segment(1);
        //$data['events'] = $this->Eventsmodel->getLeft($controller);        
        $this->load->view('events', $data);
    }
        
    function getDetails($id = null) {
            
        if($id != null){
            $data['mainContents'] = $this->Eventsmodel->getRightDetails($id);
        }
        $this->load->view('events', $data);
        
        $controller = $this->uri->segment(1);
        $data['events'] = $this->Eventsmodel->getRHSDetails(2);        
        $this->load->view($controller, $data);
    }
    
    
    
}

/* End of file events.php */
/* Location: ./application/controllers/events.php */

Full Model File
Code:
&lt;?php

class Eventsmodel extends Model {

    function __construct()
    {
        parent::__construct();
        // load database class and connect to MySQL
        $this->load->database();

    }
        
    function getLeft(){
       $query = $this->db->select('id', 'title', 'created_on');
       $query = $this->db->where('published', 'active');
       $query = $this->db->get('mcd_events');
       return $query->result();
    }
    
    function getRightDetails($id){
       $qs = "SELECT description FROM mcd_events WHERE id=$id";
       $this->load->view('events');
    }
    
    function getRHSDetails($id){
       if($id){
          $this->Eventsmodel->getRightDetails($id);
          $this->load->view('events');
       }
    }
    
    
}
?&gt;
#28

[eluser]LuckyFella73[/eluser]
Yes you are mixed up a little bit Wink

when setting an anchor you call a controller. In your
case you call a controller (event and a specified method in that
controller. In that method you can call a model to get
the data from db and send the results to your view. Thats
how a MVC basically works.
#29

[eluser]the_unforgiven[/eluser]
Right ok thought I was a little mixed up here so what's the best way to get round this having seen my code so far?
#30

[eluser]the_unforgiven[/eluser]
Bearing in mind that when the anchor is clicked on the left the description from the DB needs to be shown on the right side of the same page




Theme © iAndrew 2016 - Forum software by © MyBB