Welcome Guest, Not a member yet? Register   Sign In
How can I use again a function for another term?
#1

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?
Reply
#2

@Rajuone,

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

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?
Reply
#4

(This post was last modified: 08-29-2018, 11:01 AM by Wouter60.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB