Welcome Guest, Not a member yet? Register   Sign In
Migration Advice
#2

[eluser]Phil Sturgeon[/eluser]
After recently migrating several legacy PHP sites into CodeIgnitor, I found a very helpful way of doing things was to bung all of those nasty old function files into one big-ass helper and autoload it. That was as you go around replacing out old functions with CodeIgnitors various built-ins you can slowly strip this file down and split it up untill its gone.

As for files with mixed in PHP and HTML, put them in the controllers too. Its not practical MVC but its good to take it all one step at a time and work through untill its all correctly done.

For an example of a search function I put in one of my models, check this:

Code:
function search($keywords = '', $limit = 0, $offset = 0)
    {
        $this->db->select('gameID');
        $this->db->from('Games');
        
        if($this->input->post('q')):
            $keywords = $this->input->post('q');
        endif;
        
        // If its got spaces, split it up. If not then make an array from one entry
        $keywordArray = (strpos($keywords, ' ')) ? explode(' ', $keywords) : array($keywords);

        // Split up keywords and produce the LIKE query
        foreach($keywordArray as $keyword):
            echo $keyword;
            $this->db->orlike('gameName', $keyword);
            $this->db->orlike('description', $keyword);
        endforeach;
        
        if($this->where != '')         $this->db->where($this->where);
        if($limit > 0)                 $this->db->limit($limit, $offset);
        if($this->orderBy != '')     $this->db->orderby($this->orderBy);
        else                        $this->db->orderby('gameName', 'ASC');
        
            
        $query = $this->db->get();
        echo $this->db->last_query();
        $this->where = "";
        $this->orderBy = "";
        
        $data = array();

        foreach($query->result_array() as $row):
            $data[] = $this->get($row['gameID']);
        endforeach;

        $query->free_result();
        return $data;
    
    }

Have been meaning to convert it to a proper library so I dont have one of these in each of my models, but good enough for now.


Messages In This Thread
Migration Advice - by El Forum - 07-12-2007, 02:51 PM
Migration Advice - by El Forum - 07-16-2007, 07:28 PM
Migration Advice - by El Forum - 07-16-2007, 08:16 PM
Migration Advice - by El Forum - 07-17-2007, 05:11 AM
Migration Advice - by El Forum - 07-17-2007, 04:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB