zoukankan      html  css  js  c++  java
  • Yii2 Lesson

    数据库新建表users

    /* show create table tablename */
    CREATE TABLE `users` (
     `user_id` int(11) NOT NULL AUTO_INCREMENT,
     `username` varchar(100) NOT NULL,
     `password` varchar(32) NOT NULL,
     PRIMARY KEY (`user_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
    
    

    新建模型类 models/User.php

    <?php
    namespace appmodels;
    
    use yiidbActiveRecord;
    
    class Users extends ActiveRecord
    {
    
    }
    

    创建控制器和方法controllers/UsersController.php

    <?php
    namespace appcontrollers;
    
    use yiiwebController;
    use appmodelsUsers;
    
    class UsersController extends Controller
    {
        public function actionIndex()
        {   
            $users = Users::find()->all();
            return $this->render('index',['users'=>$users]);
        }   
    }
    
    

    创建显示类 views/users/index.php

    <?php
    
    foreach($users as $user)
    {
        echo $user->username."<br>";
    }
    
  • 相关阅读:
    代码查错1
    代码查错
    垃圾回收器
    面试题(操作语句)
    面试题(JVM加载机制)
    面试题(线程)
    异常
    IO流
    es5 学习笔记
    ECMAScript5 Object的新属性方法
  • 原文地址:https://www.cnblogs.com/JsonM/p/7211768.html
Copyright © 2011-2022 走看看