Как вводить угловые данные в MongoDB с помощью PHP Codeigniter - PullRequest
0 голосов
/ 14 января 2019

Я начну использовать Angular Framework, MongoDB и Codeigniter. Я хочу спросить, что угловая базовая форма ввода в поле: Имя: Электронная почта: Адрес :. Я хочу, чтобы три поданных данных вставлялись в MongoDB. Данные, которые не являются прямыми, отправляются в MongoDB, сначала перенос данных в PHP Codeigniter и поле Name, а затем - в базу данных (MongoDB). Я уже использовал Nodejs.

скажите, пожалуйста, что на самом деле представляет собой код передачи данных Angular или данные? Введите код.


ветвления list.component.ts

      name: {
        title: 'Branch-Name',
        width: '40%'
      },
       Address: {
        title: 'Address',
        width: '40%'
      },
    }
  };

  constructor(private router: Router, private generalApiService: GeneralApiService
    , private route: ActivatedRoute, private modalService: NgbModal) { }

  ngOnInit() {
    this.generalApiService.getAll(this.apiUrl).subscribe(res => {
      this.branch = res;
    });
  }
---------------------------------------------------------------
pages.module.ts
---------------------------------------------------------------
import { NgModule } from '@angular/core';

import { PagesComponent } from './pages.component';
import { DashboardModule } from './dashboard/dashboard.module';
import { PagesRoutingModule } from './pages-routing.module';
import { ThemeModule } from '../@theme/theme.module';
import { MiscellaneousModule } from './miscellaneous/miscellaneous.module';
import { ModalComponent } from './components/modal.component';

const PAGES_COMPONENTS = [
  PagesComponent,
  ModalComponent
];

@NgModule({
  imports: [
    PagesRoutingModule,
    ThemeModule,
    DashboardModule,
    MiscellaneousModule,

  ],
  entryComponents:[
    ModalComponent
  ],
  declarations: [
    `...PAGES_COMPONENTS,`
  ],
})
export class PagesModule {
}

----------------------------------------------------------------------
`mongo_db.php in CI
---------------------------------------------------------------------
$config['mongo_db']['active'] = 'default';

$config['mongo_db']['default']['no_auth'] = true;
$config['mongo_db']['default']['hostname'] = 'localhost';
$config['mongo_db']['default']['port'] = '27017';
$config['mongo_db']['default']['username'] = '';
$config['mongo_db']['default']['password'] = '';
$config['mongo_db']['default']['database'] = 'myancon';
$config['mongo_db']['default']['db_debug'] = true;
$config['mongo_db']['default']['return_as'] = 'array';
$config['mongo_db']['default']['write_concerns'] = (int) 1;
$config['mongo_db']['default']['journal'] = true;
$config['mongo_db']['default']['read_preference'] = 'primary';
$config['mongo_db']['default']['read_concern'] = 'local'; //'local', 'majority' or 'linearizable'
$config['mongo_db']['default']['legacy_support'] = false;

------------------------------------------------------------------
branch.php Controller in CI
-------------------------------------------------------------------
class Branches extends REST_Controller
{
  public function index_post() {
        if ($this->input->method(TRUE) === 'POST') {
            $_POST = json_decode(file_get_contents('php://input'), true);
            $data = array(
                "branchname" => $this->input->post('branchname')
                ,"address" => $this->input->post('address')
                ,"phone" => $this->input->post('phone')
        );

            if ($this->input->post('_id') != null) {
                $_id = $this->input->post("_id");

            } else {
                $this->Branch_model->add($data);
            }

            $this->response([], 201);
        }
    }
}

---------------------------------------------------------------------
Branch_model.php
--------------------------------------------------------------------
class Branch_model extends CI_Model
{
 public function add($data) {
        return $this->`mongo`_db->insert("branch", $data);
    }
}

Код подключения к Angular Data и код вставки данных, пожалуйста, объясните с именем файла Angular!

`

...