Domestic PHP development framework myqee Quick Start tutorial

Source: Internet
Author: User
Tags php foreach
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 http://www.bitsCN.com/article/52123.htm

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.