CodeIgniter Forums

Full Version: How can I use again a function for another term?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Controller 


    public function __construct() {
        parent::__construct();
        $this->load->model('HomeModel');
    }

    public function insertPostData() {
        $data['post_title']= $this->input->post('post_title');
        $data['post']= $this->input->post('post');
        $postImg= $_FILES['post_img']['name'];
        $Img_target_file="uploads/" .basename($postImg);
        if(file_exists($Img_target_file)){
            $Img_target_file="uploads/" . $data['post_img'] .basename($postImg);
        }
        move_uploaded_file($_FILES['post_img']['tmp_name'], $Img_target_file);
        $data['post_img']=$Img_target_file;
//        var_dump($data);
//        die();
        $insertId= $this->HomeModel->postData('article',$data);
        if($insertId){
            redirect(site_url('Admin/dashboard'));
        }
    }


Model


class HomeModel extends CI_Model {
    
    public function postData($table=null, $data=null) {
        $this->load->database();
        $this->db->insert($table,$data);
        return $this->db->insert_id();
    }
}




I want to use my insertPostData again for my another term. how can i do that?
@Rajuone,

You could assign the values to a session variable which will be always available during the users session.
What do you mean by another term?

Do you want to use same function, but have different URL?

Or do you want same function to use different model/table?
Another term?  Huh

If you share php code, please press the PHP button on the button bar of the text editor in this forum. Paste the code between the opening and closing tag for php code.

The result will look like this:
PHP Code:
<?php 
echo "Paste code in here";
?>

So much better readable than plain text.