CodeIgniter Forums
First Time Using Models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: First Time Using Models (/showthread.php?tid=13954)



First Time Using Models - El Forum - 12-12-2008

[eluser]Bl4cKWid0w[/eluser]
I'm using models to create a wiki. I get a php syntax error saying that it can't redeclare class Wiki on line 59. Line 59 is empty. I already made sure that all my if statements, etc were closed. Here is my code:
Code:
<?php

class Wiki extends Model {
    
    var $title;
    var $author;
    var $date;
    var $body;
    var $lasteditby;
    var $lastediton;
    var $views;
    var $categoryID;
    
    function wiki(){
        
        parent::Model();
        
    }
    
    function create($title, $author, $date, $body, $lasteditby, $lastediton, $categoryID){
        
        $insert = array(
                        'title' => $title,
                        'author' => $author,
                        'date' => $date,
                        'body' => htmlentities($body),
                        'lasteditby' => $lasteditby,
                        'lastediton' => $lastediton,
                        'categoryID' => $categoryID
                        );
        $query = $this->db->insert('wikis',$insert);
        
    }
    
    function get_new(){
        
        $query = $this->db->query("SELECT * FROM wikis ORDER BY wikiID DESC LIMIT 5");
        if($query->num_rows() == 0){
            echo "<h1>There are no wiki's to display at this time</h1>";
        } else {
             foreach($query->result() as $wiki){
                 echo "<li>".anchor('http://www.unholydesigns.com/technicliche/wiki/article/'.$wiki->wikiID, $wiki->title)."</li>";
             }
        }
        
    }
    
    function get_popular(){
        
        $query = $this->db->query("SELECT * FROM wikiws ORDER BY views");
        if($query->num_rows() == 0){
            echo "<h1>There are no wiki's to display at this time</h1>";
        } else {
            foreach($query->result() as $wiki){
                echo "<li>".anchor('http://www.unholydesigns.com/technicliche/wiki/article/'.$wiki->wikiID, $wiki->title)."</li>";
            }
        }
    }
}



First Time Using Models - El Forum - 12-12-2008

[eluser]gstjohn[/eluser]
Try capitalizing your constructor.

Code:
function Wiki(){
    parent::Model();    
}



First Time Using Models - El Forum - 12-12-2008

[eluser]gstjohn[/eluser]
Double post...sorry!

Do you have a controller named 'Wiki'? That is likely causing the redeclaration.


First Time Using Models - El Forum - 12-12-2008

[eluser]missionsix[/eluser]
[quote author="gstjohn" date="1229144916"]Double post...sorry!

Do you have a controller named 'Wiki'? That is likely causing the redeclaration.[/quote]

it IS whats causing the problem. Hes just looking in the wrong place. Check your controller where you are loading the wiki model, that is where the class declaration collides.


First Time Using Models - El Forum - 12-13-2008

[eluser]Bl4cKWid0w[/eluser]
Yeah, that was it. Thanks.