Главная Случайная страница


Полезное:

Как сделать разговор полезным и приятным Как сделать объемную звезду своими руками Как сделать то, что делать не хочется? Как сделать погремушку Как сделать так чтобы женщины сами знакомились с вами Как сделать идею коммерческой Как сделать хорошую растяжку ног? Как сделать наш разум здоровым? Как сделать, чтобы люди обманывали меньше Вопрос 4. Как сделать так, чтобы вас уважали и ценили? Как сделать лучше себе и другим людям Как сделать свидание интересным?


Категории:

АрхитектураАстрономияБиологияГеографияГеологияИнформатикаИскусствоИсторияКулинарияКультураМаркетингМатематикаМедицинаМенеджментОхрана трудаПравоПроизводствоПсихологияРелигияСоциологияСпортТехникаФизикаФилософияХимияЭкологияЭкономикаЭлектроника






Configuration and migration





All of the configuration files for the Yii framework are stored in the app/config directory. Each option in every file is documented, so feel free to look through the files and get familiar with the options available to you.

It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver on your local development machine than on the production server. It is easy to accomplish this using environment based configuration.

In configuration folder located database.php file which is used to configure the database of project. For my project I have configured my database for using mysql.

As you can see in figure 1 I have used localhost with username “root” and database name is “serjan”. Also charset is set to “utf8”.

Figure 1. Database configuration

Configurations also can be made to authorization, mailing, and session services. In app.php file you can configure locale for the project. The application locale determines the default locale that will be used by the translation service provider. You are free to set this value to any of the locales which will be supported by the application. And “feedback_locale” determines the locale to use when the current one is not available. You may change the value to correspond to any of the language folders that are provided through your application.

When using environment configuration, you may want to "append" environment service providers to your primary app configuration file. However, if you try this, you will notice the environment appproviders are overriding the providers in your primary app configuration file. To force the providers to be appended, use the append_config helper method in your environment app configuration file.

For "real" applications, it is advisable to keep all of your sensitive configuration out of your configuration files. Things such as database passwords, Stripe API keys, and encryption keys should be kept out of your configuration files whenever possible. So, where should we place them? Thankfully, Yii provides a very simple solution to protecting these types of configuration items using "dot" files.

Figure 2. Code

 

 

Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema.

To create a migration, you may use the "migration:make” command on CMD. The migration will be placed in your app/database/migrations folder, and will contain a timestamp which allows the framework to determine the order of the migrations. If needed, you may also specify a “--path” option when creating the migration. The path should be relative to the root directory of your installation.

When you develop a new application, your data model changes frequently, and each time the model changes, it gets out of sync with the database. You have configured the Entity Framework to automatically drop and re-create the database each time you change the data model. When you add, remove, or change entity classes or change context, the next time you run the application it automatically deletes your existing database, creates a new one that matches the model, and seeds it with test data.

This method of keeping the database in sync with the data model works well until you deploy the application to production. When the application is running in production it is usually storing data that you want to keep, and you don't want to lose everything each time you make a change such as adding a new column. The code first migrations feature solves this problem by enabling Code First to update the database schema instead of dropping and re-creating the database. In this tutorial, you'll deploy the application, and to prepare for that you'll enable Migrations.

Once you have configured your migration you can use “php artisan migrate” command to run your migration. If something went wrong you also have “php artisan migrate:rollback” command. It will roll back last migration operation.

Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.

Yii also includes a simple way to seed your database with test data using seed classes. It is useful when you need to test your database and tables by inserting some amount of data. All seed classes are stored in app/database/seeds. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UserTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order. In MVC 5 applications you may want to seed the database with initial users for various reasons. You may want default users and roles added as part of the application. In this post, we will take a look at how to seed the database with default users.

The MVC 5 application uses ASP.Net Identity 2.0 to manage users, roles and identities. ASP.Net Identity 2.0 uses the Entity framework code first approach to create a database. To seed the database, first you need to enable migration on the database.

Example of DatabaseSeed class is shown in figure 3:

Figure 3. Database Seeder

 

 

To seed your database, you may use the “db:seed” command on CMD. It will fill tables by various data. By default, the “db:seed” command runs the DatabaseSeeder class, which may be used to call other seed classes. However, you may use the --class option to specify a specific seeder class to run individually.

 

Date: 2016-07-22; view: 303; Нарушение авторских прав; Помощь в написании работы --> СЮДА...



mydocx.ru - 2015-2024 year. (0.006 sec.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав - Пожаловаться на публикацию