This article mainly introduces the domestic PHP development framework myqee beginner quick start tutorial, myqee Chinese name Mai Qi PHP framework, there are many advanced development features, you can refer to below
This article mainly introduces the domestic PHP development framework myqee beginner quick start tutorial, myqee Chinese name Mai Qi PHP framework, there are many advanced development features, you can refer to below
I. environment.
My environment is the flagship version of win7 32bit. xampp1.7.4 (php version 1.8.x is too high, I personally think php 5.3X is more practical) + the latest version of mq. The focus is on configuring virtual machines,
Reference
The local xampp is installed on the D Drive and my configuration is provided: virtual machine configuration file path D: \ xampp \ apache \ conf \ extra \ httpd-vhosts
The Code is as follows:
# Mq
DocumentRoot "D:/xampp/htdocs/mq /"
ServerName mq
Options Indexes FollowSymLinks between des ExecCGI
AllowOverride All
Order allow, deny
Allow from all
DocumentRoot "D:/xampp/htdocs /"
ServerName localhost
Host Configuration File Location
C: \ Windows \ System32 \ drivers \ etc \ hosts. ics
No hosts is found on the local machine. You can change hosts. ics.
2. Create a myqee Project
1. download the latest version of myqee, github you know.
Decompress the package to the D:/xampp/htdocs/mq folder (consistent with the virtual machine configuration ).
Change config. new. php to config. php.
Another. htacess is needed. I can't download it from github. The content that needs to be written in the official document is as follows:
The Code is as follows:
RewriteEngine On
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule. * index. php [PT, L]
Copy one copy to the wwwroot directory.
A. Create a project, open config. php In the root directory, and add an s project,
The configuration is as follows (before the default configuration)
The Code is as follows:
'S '=> array
(
'Name' => 'default Project', // name
'Dir' =>'s ', // directory
'Isuse' => true, // whether to enable
'Url' => '/',
),
B. Create the directory s under projects. Copy defautl and rename it for convenience.
Create a simple controller helloworld. controller. php In controllers under the s directory.
The content is as follows:
The Code is as follows:
<? Php
Class Controller_HelloWorld extends Controller
{
/**
* Test
*/
Public function action_default ()
{
Echo 'helloworld ';
}
}
Open the browser, enter mq/index. php/helloworld, and check hellowold.
In the development environment, we recommend that you enable the debug function of myqee and add it in php. ini.
The Code is as follows:
; [MyQEE]
Myqee. debug = On
Used with firefox + firebug.
3. display the content in the database.
Hello world is so simple that it doesn't make much sense in actual development. Let's take a look at it, read data from the database, and display it in the corresponding view.
A. Create a config. php file in the s root directory and write the corresponding database configuration. The content is as follows:
The Code is as follows:
<? Php
/** Database config */
$ Config ['database'] ['default'] = array
(
'Type' => 'mysql ',
'Connection' => array
(
'Hostname' => '2017. 0.0.1 ',
'Database' => 'rabbit ',
'Username' => 'rabbit ',
'Password' => '000000', 'persistent' => false,
),
'Table _ prefix' => '',
'Charset' => 'utf8 ',
'Caching' => false,
'Filing' => true,
);
Here, I have created an mq library in mysql and created a table wh_list.
The ddl of wh_list is as follows (the content is added by yourself ).
The Code is as follows:
Create table 'wh _ List '(
'Id' int (11) not null AUTO_INCREMENT,
'Name' varchar (32) COLLATE utf8_unicode_ci default null,
Primary key ('id '),
Unique key 'username' ('username') USING BTREE
) ENGINE = MyISAM default charset = utf8 COLLATE = utf8_unicode_ci;
B. Starting from model.
Create the models directory under the s directory, and create a wh. model. php with the following content:
The Code is as follows:
<? Php
Class Model_Wh extends Model
{
Static function get_list ()
{
$ Db = Database: instance ();
$ SQL = 'select * FROM wh_list ';
$ Arr = $ db-> query ($ SQL)-> as_array ();
Return $ arr;
}
}
Modify the helloworld controller as follows:
The Code is as follows:
<? Php
Class Controller_HelloWorld extends Controller
{
/**
* Test
*/
Public function action_default ()
{
$ View = new View ('wh ');
$ Arr = Model_Wh: get_list ();
$ View-> set ('wh ', $ arr );
$ View-> render ();
}
}
Don't be excited. If you click mq/index. php/helloworld in the browser just now, an error will be reported, and the view does not exist.
In views, create wh. view. php
The content is as follows:
The Code is as follows:
<? Php foreach ($ wh as $ w) {?>
<? Php echo $ w ['name']?>
<? Php }?>
Refresh and you will see the 'name' column in The wh_list table.
Oh, is it a sense of accomplishment.
The beginner's quick start tutorial is written here first, and the declaration is used only to give the beginner a Quick Start experience framework.
,