bertugfahriozer/ci4mongodblibrary

Codeigniter 4 MongoDB library & Common Model

1.1.4 2023-02-05 01:23 UTC

This package is auto-updated.

Last update: 2024-04-05 04:30:37 UTC


README

##Sistem Gereksinimleri

  • PHP 7.3 veya 8.0^
  • MongoDB PHP Driver 1.8^

Kurulum

Mongo Driver ve Composer'a sisteminize kurmuş olmalısınız. Kurulum için şu bağlantıları izleyin:

Bir config dosyası oluşturmalısınız. Dosya oluşturduğunuzda, php etiketi için boşlukları silin. (app/Config/MongoConfig.php)

Uzak Bağlantı için srv değişkenine yorum satırındakini veri kullanılabilir veya boş bırakılabilir. authMechanism değişkeni bağlantı yapılırken gereken güvenlik protokolünü belirtmeniz için oluşturulmuştur.

Eğer isterseniz başka bir veritabanına bağlanmak için model içinde $dbVar=new Mongo('dbName'). bu sayede tek bir Ci4 uygulaması içinde birden çok veritabanına müdehale edebilirsiniz.

<?php namespace App\Config;

use CodeIgniter\Config\BaseConfig;

class MongoConfig extends BaseConfig
{
    public $dbInfo = [];

    public function __construct()
    {
        $this->dbInfo = [
            'default' => (object)[
                'db' => '', //your database
                'hostname' => "",//127.0.0.1 if you use remote server you should change host address
                'userName' => "",
                'password' => "",
                'prefix' => '',
                'port' => "",//27017 if you use different port you should change port address
                'srv' => 'mongodb',//mongodb+srv
                //SCRAM-SHA-256 - SCRAM-SHA-1
                'authMechanism' => "SCRAM-SHA-1",
                'db_debug' => TRUE,
                'write_concerns' => (int)1,
                'journal' => TRUE,
                'read_preference' => 'primary',
                'read_concern' => 'local', //'local', 'majority' or 'linearizable'
                'ca_file'=>[]//['ca_file' => '/usr/local/etc/openssl/cert.pem']
            ]
        ];
    }
}

composer require bertugfahriozer/ci4mongodblibrary

Eğer Composer ile yükledikten sonra direkt devam etmek istiyorsanız namespace düzeni şu şekilde :

use ci4mongodblibrary\Models\CommonModel;

use ci4mongodblibrary\Libraries\Mongo;

Manuel kurulum istiyorsanız aşağıdaki adımları takip edebilirsiniz.

Codeigniter 4 projenize dosyaları taşıyabilirsiniz ve namespace değiştirmeniz gerekir =>

app/Libraries/Mongo.php,
app/Config/MongoConfig.php,
app/Models/CommonModel.php.

68747470733a2f2f62657274756766616872696f7a65722e636f6d2f6173736574732f696d616765732f67616c6c6572792f424d432d6c6f676f776f72646d61726b2d426c61636b2e6a7067

Codeigniter 4 MongoDB Library & Common Model

##System Requirements

  • PHP 7.3 veya 8.0^
  • MongoDB PHP Driver 1.8^

Installation

You must have Mongo Driver and Composer. Follow these links for installation:

You must create a config file. When you create file, delete spaces for php tag. (app/Config/MongoConfig.php)

For Remote Connection, the data in the comment line can be used or left blank in the srv variable. The authMechanism variable is created to specify the required security protocol when connecting.

If you want to connect to another database, $dbVar=new Mongo('dbName') in the model. In this way, you can intervene in multiple databases within a single Ci4 application.

<?php namespace App\Config;

use CodeIgniter\Config\BaseConfig;

class MongoConfig extends BaseConfig
{
    public $dbInfo = [];

    public function __construct()
    {
        $this->dbInfo = [
            'default' => (object)[
                'db' => '', //your database
                'hostname' => "",//127.0.0.1 if you use remote server you should change host address
                'userName' => "",
                'password' => "",
                'prefix' => '',
                'port' => "",//27017 if you use different port you should change port address
                'srv' => 'mongodb',//mongodb+srv
                //SCRAM-SHA-256 - SCRAM-SHA-1
                'authMechanism' => "SCRAM-SHA-1",
                'db_debug' => TRUE,
                'write_concerns' => (int)1,
                'journal' => TRUE,
                'read_preference' => 'primary',
                'read_concern' => 'local', //'local', 'majority' or 'linearizable'
                'ca_file'=>[]//['ca_file' => '/usr/local/etc/openssl/cert.pem']
            ]
        ];
    }
}

composer require bertugfahriozer/ci4mongodblibrary

If you want to continue directly after installing with Composer, the namespace layout is as follows:

use ci4mongodblibrary\Models\CommonModel;

use ci4mongodblibrary\Libraries\Mongo;

if do you want manual install you can follow these steps.

You can move files in your Codeigniter 4 project and you must change namespaces =>

app/Libraries/Mongo.php,
app/Config/MongoConfig.php,
app/Models/CommonModel.php.

68747470733a2f2f62657274756766616872696f7a65722e636f6d2f6173736574732f696d616765732f67616c6c6572792f424d432d6c6f676f776f72646d61726b2d426c61636b2e6a7067