Domestic PHP development framework myqee novice quick start tutorial

  • 2021-07-09 07:30:11
  • OfStack

1. Environment.

My environment is the flagship version of win7 32bit. I used xampp 1.7. 4 (1.8. x version of php is too high, and I think php 5.3 X is more practical) + the latest version of mq. The emphasis is on configuring virtual machines.
Reference was made to https://www.ofstack.com/article/52123. htm

The native xampp is installed on the D disk, giving my configuration: virtual machine configuration file path D:\ xampp\ apache\ conf\ extra\ httpd-vhosts


#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 Profile Location
C:\Windows\System32\drivers\etc\hosts.ics
This machine did not find hosts, change hosts. ics is also possible.

2. Create a new myqee project

1. Download the latest version of myqee, github, you know.
Unzip into the D:/xampp/htdocs/mq folder (with Virtual Machine Configuration 1).
Modify config. new. php to config. php
There is also a need for one. htacess, I use github downloaded down the 1 straight not, need to use the official document to write the one. The content is as follows


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [PT,L]

Copy of copy1 to wwwroot directory.
a. Create a new project, open config. php in the root directory, add a new s project,
The configuration is as follows (before the default configuration)


's' => array
    (
        'name' => ' Default project ', // Name
        'dir' => 's', // Directory
        'isuse' => true, // Enable or not
        'url' => '/',
 ),

b. projects under the new directory s, for convenience, directly copy defautl and rename.
Create a new simplest controller helloworld. controller. php in controllers under s directory
The contents are 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, successful.
In the development environment, it is recommended to turn on the debug function of myqee and add it in php. ini

;[MyQEE]
myqee.debug=On

Used in conjunction with firefox + firebug.

3. Display the contents of the database.

hello world is too simple to make sense in actual development. Strike while the iron is hot. Get some dry goods, read the data from the database, and display it in the corresponding view.
a. New config. php Place in the s root directory and write to the corresponding database configuration. 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 build an mq library in mysql and a table wh_list
wh_list has the following ddl (add the content yourself).


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. model.
Under the s directory, create a new models directory and create a new wh. model. php with the following contents:


<?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. Modify 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 get excited, if you brush the mq/index.php/helloworld just now, you will definitely report an error. There is no view.
In views, create wh. view. php
The contents are as follows:


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

When you refresh, you can see the contents of the ` name ` column of the wh_list table.
Hehe, is it a sense of accomplishment?
Beginners' tutorial is written here first, and it is stated that this is only for beginners to get started quickly.


Related articles: