Native PHP Development Framework Myqee Beginner Quick Start Tutorial _php instance

Source: Internet
Author: User
Tags php foreach
I. Environment.

The author's environment is Win7 32bit flagship version. xampp1.7.4 (1.8.x version of the PHP version is too high, personally think PHP 5.3X more practical) +mq the latest version. The focus is on configuring the virtual machine,
Reference to the Http://www.php.net/article/52123.htm

The native XAMPP is installed on the D drive and gives me the configuration: Virtual machine profile Path D:\xampp\apache\conf\extra\httpd-vhosts

Copy the Code code as follows:
#mq

DocumentRoot "d:/xampp/htdocs/mq/"
ServerName MQ

Options Indexes FollowSymLinks includes 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
The machine did not find the hosts, change Hosts.ics is also possible.

Two. Create a new Myqee project

1. Download the latest version of Myqee,github you know.
Unzip to the D:/xampp/htdocs/mq folder (consistent with the virtual machine configuration).
Modify config.new.php to config.php
There is a need for a. Htacess, the one I downloaded from GitHub has not been available and needs to be written in the official documentation. The content is as follows
Copy the Code code as follows:
Rewriteengine on
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule. * index.php [pt,l]

Copy a copy to the Wwwroot directory.
A. Create a new project, open the root directory of config.php, add an S project,
Configured as follows (before the default configuration)

Copy the Code code as follows:
' s ' = = array
(
' Name ' = ' Default item ',//Name
' dir ' = ' s ',//directory
' Isuse ' = true,//whether enabled
' url ' = '/',
),

B.projects the following new directory S, for convenience, directly copy defautl and rename.
Create a new simplest controller in the S directory Controllers helloworld.controller.php
The contents are as follows

Copy the Code code as follows:
<?php
Class Controller_helloworld extends Controller
{
/**
* Test
*/
Public Function Action_default ()
{
Echo ' HelloWorld ';
}
}

Open the browser, enter Mq/index.php/helloworld, see Hellowold, success.
In the development environment, it is recommended to turn on the debug function of Myqee and join in php.ini
Copy the Code code as follows:
; [Myqee]
Myqee.debug=on

Use with Firefox +firebug.

Three. Display the contents of the database.

Hello world is so simple that it doesn't make any sense in actual development. Get some dry goods, read the data from the database, and display it in the corresponding view.
A. The new config.php is placed in the S root directory and written to the corresponding database configuration. The contents are as follows:
Copy the Code code as follows:
<?php
/**database config*/
$config [' database '] [' default '] = array
(
' Type ' = ' MySQL ',
' Connection ' = array
(
' Hostname ' = ' 127.0.0.1 ',
' Database ' = ' MQ ',
' Username ' = ' MQ ',
' Password ' = ' 123456 ', ' persistent ' and false,
),

' Table_prefix ' = ',
' CharSet ' = ' utf8 ',
' Caching ' = False,
' Profiling ' = true,
);

Here I built an MQ library in MySQL and built a table wh_list
The DDL for Wh_list is as follows, (the content is added by itself).
Copy the Code code as follows:
CREATE TABLE ' Wh_list ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar (+) 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.model the whole.
Create a new models directory under the S directory and create a new wh.model.php content as follows:

Copy the Code code 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 above. The contents are modified as follows:

Copy the Code code 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 in browsing brush just Mq/index.php/helloworld, certainly will error, view not.
In views, new wh.view.php
The contents are as follows:
Copy the Code code as follows:
<?php foreach ($wh as $w) {?>
<?php echo $w [' name ']?>
<?php}?>

Under Refresh, you can see the ' name ' column of the Wh_list table.
Oh, is not a very fulfilling feeling.
Beginner's Introductory tutorial is written here, under the statement that this is just for beginners to get started with the framework of the experience.

  • 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.