无法从角度4视图中获取codeigniter中的数据

时间:2022-05-18 04:31:07

I am using angular 4 for front end and CodeIgniter at the backend. At the angular end, there is a form that has some input values and images that I need to fetch at CodeIgniter end so that they can be saved in the database. But for an image, I wish to save it in a folder and then save its path in a database

我在后端使用角度4,在后端使用CodeIgniter。在角度端,有一个表单具有一些输入值和图像,我需要在CodeIgniter端获取它们,以便它们可以保存在数据库中。但是对于图像,我希望将其保存在文件夹中,然后将其路径保存在数据库中

Form code

表格代码

<form ngNativeValidate [formGroup]="form" (ngSubmit)="onSubmitadd()" class="form-horizontal">
    <input type="text" class="form-control"  name="title" id="title" formControlName="title" minlength="10" maxlength="150" required>

    <input type="file" id="avatar" (change)="onFileChange($event)" #fileInput required>

    <button type="submit"  class="demo-loading-btn btn red savebtn">Save</button>
</form>



 onSubmitadd() {
    const formModel = this.form.value;
    this.loading = true;
     this.http.post('http://www.localhost/litehires/company/profile',formModel ,{
      })
        .subscribe(
          res => {
            console.log(res);
            $("#add-data .close").click();
            this.listBanner();
        },
          err => {
            console.log("Error occured");
          }
        );
  }

Controller Code

控制器代码

public function profile()   
      {  
        $res = $this->input->post('formModel');
        return $res;
      }

While checking in a console the data is getting passed in formModel but I am not able to fetch the data in a controller. Can anyone please tell how to fetch the data and image so that I can process it further

在检入控制台时,数据将在formModel中传递,但我无法获取控制器中的数据。任何人都可以告诉我如何获取数据和图像,以便我可以进一步处理它

1 个解决方案

#1


0  

You will have to use php input stream for this

您将不得不使用php输入流

$data = json_decode(file_get_contents('php://input'), true);

$ data = json_decode(file_get_contents('php:// input'),true);

public function profile()   
{  
  $res = json_decode(file_get_contents('php://input'), true);
}

Let me know if it is unclear as I have been using it in my controllers

如果不清楚我是否在我的控制器中使用它,请告诉我

#1


0  

You will have to use php input stream for this

您将不得不使用php输入流

$data = json_decode(file_get_contents('php://input'), true);

$ data = json_decode(file_get_contents('php:// input'),true);

public function profile()   
{  
  $res = json_decode(file_get_contents('php://input'), true);
}

Let me know if it is unclear as I have been using it in my controllers

如果不清楚我是否在我的控制器中使用它,请告诉我