CodeIgniter Forums
How can I use again a function for another term? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How can I use again a function for another term? (/thread-71556.html)



How can I use again a function for another term? - Rajuone - 08-28-2018

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?


RE: How can I use again a function for another term? - php_rocs - 08-29-2018

@Rajuone,

You could assign the values to a session variable which will be always available during the users session.


RE: How can I use again a function for another term? - Pertti - 08-29-2018

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?


RE: How can I use again a function for another term? - Wouter60 - 08-29-2018

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.