Domestic PHP Development Framework Myqee Novice Quick Start Tutorial _php instance

Source: Internet
Author: User
Tags php foreach

I. Environment.

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

This machine xampp installed in D disk, give my configuration: virtual machine configuration file path D:\xampp\apache\conf\extra\httpd-vhosts

Copy Code code as follows:

#mq
<virtualhost *:80>
DocumentRoot "d:/xampp/htdocs/mq/"
ServerName MQ
<directory "d:/xampp/htdocs/mq/" >
Options Indexes followsymlinks Includes execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
</VirtualHost>
<virtualhost *:80>
DocumentRoot "d:/xampp/htdocs/"
ServerName localhost
</VirtualHost>

Host configuration file location
C:\Windows\System32\drivers\etc\hosts.ics
This machine did not find hosts, change Hosts.ics is also possible.

Two. Create a new Myqee project

1. Download the latest version myqee,github you know.
Extract into the D:/xampp/htdocs/mq folder (consistent with the virtual machine configuration).
Modify config.new.php to config.php
There's still a need for one. htacess, I downloaded it with GitHub. The one that needs to be written in the official document. The contents are as follows

Copy 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,
Configuration is as follows (before default configuration)

Copy Code code as follows:

' s ' => array
(
' Name ' => ' Default item ',//Name
' dir ' => ' s ',//directory
' Isuse ' => true,//is enabled
' URL ' => '/',
),

B.projects new directory S, for convenience, direct replication defautl and rename.
Create the simplest controller in the controllers under s directory helloworld.controller.php
The contents are as follows

Copy 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 feature of Myqee, joining in php.ini
Copy Code code as follows:

; [Myqee]
Myqee.debug=on

With Firefox +firebug use.

Three. Display the contents of the database.

Hello world is so simple that there is no point in actual development and the iron is hot. Have 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 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 ' => false,
),

' Table_prefix ' => ',
' CharSet ' => ' UTF8 ',
' Caching ' => false,
' Profiling ' => true,
);

Here I built an MQ library in MySQL and built a table wh_list
Wh_list's DDL is as follows (content added).

Copy 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 in the S directory and create a new wh.model.php content as follows:

Copy 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 content is modified as follows:

Copy 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 ();
}
}

Do not be excited, if in the browsing brush just mq/index.php/helloworld, certainly will be an error, the view is not.
In views, new wh.view.php
The contents are as follows:

Copy Code code as follows:

<?php foreach ($wh as $w) {?>
<?php echo $w [' name ']?>
<?php}?>

Refresh to see the ' name ' column contents of the Wh_list table.
Oh, is not a very fulfilling feeling. The
Beginner's tutorial is written here first, and this is just a quick start to feel frame for beginners.

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.