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

[eluser]the_unforgiven[/eluser]
So theoretically speaking I could use my index method like so to do so??:

Code:
function index() {
        
    // Get UL list for navigation
       $data['events'] = $this->Eventsmodel->getLeft();
            
       $this->load->view('events', $data);
}

Or what would be the best way?
#32

[eluser]LuckyFella73[/eluser]
Yes that should work. But if you click at one of the anchors
you again call your controller but an other method- you want
to get the details of one event, right?
So your event-links should look like:

<a >Event with ID 1</a>
<a >Event with ID 2</a>

or whatever your ids look like. That should work
#33

[eluser]the_unforgiven[/eluser]
Yes my links look like so: /events/2 in URl

or view source ->
Code:
<div id="events">    
    <h3><a href="http://localhost/mcd/events/2">date</a></h3>

    <h3><a href="http://localhost/mcd/events/3">date</a></h3>
</div>
But when clicked page not found 404
#34

[eluser]LuckyFella73[/eluser]
Aaargh, my code was filered ...

your links should look like
<+a + href="projectroot/events/getDetails/1"> Event ID 1</+ a +>
#35

[eluser]the_unforgiven[/eluser]
Yer they do

Code:
<h3><a href="http://localhost/mcd/events/getDetails/2">date</a></h3>

With the getDetails or without stil comes out the same, shows no errors but when the link is clicked shows 404
#36

[eluser]the_unforgiven[/eluser]
Sorry now when clciked I get

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Eventsmodel::$Eventsmodel

Filename: models/eventsmodel.php

Line Number: 27
#37

[eluser]the_unforgiven[/eluser]
And my model looks like:

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){
          $data['events'] = $this->Eventsmodel->getRightDetails($id);
          $this->load->view('events');
       }
    }    
}
?&gt;
#38

[eluser]LuckyFella73[/eluser]
Change this:
Code:
$this->Eventsmodel->getRightDetails($id);

// $this->Eventsmodel-> // only needed when calling model-method from controller

to:
Code:
$this->getRightDetails($id);
#39

[eluser]the_unforgiven[/eluser]
Ok done that thanks!!

Again another two
errors

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: events

Filename: views/events.php

Line Number: 78
---------------------------
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/events.php

Line Number: 78

This is the section where line 78 is:

Code:
<div id="events">    
&lt;?php //echo "<pre>";
//print_r($events);
//echo "</pre>";
?&gt;
    &lt;?php

    foreach($events as $item) :
    
    ?&gt;
    <h3>&lt;?php echo anchor('events/getDetails/'.$item->id, 'date'); ?&gt;</h3>
    &lt;?php endforeach; ?&gt;




</div>
#40

[eluser]LuckyFella73[/eluser]
Be sure to pass the $data['events'] to the view where you
get the rror message. You view seems not to "find" the
variable/array $events.




Theme © iAndrew 2016 - Forum software by © MyBB