[moka同学笔记]yii2.0查询数据库】的更多相关文章

  一. [:id占位符]使用 $results = Test::findBySql($sql,array(':id'=>'1 or 1=1))->all()   二. [id=1]  选出id为1的数据 $results = Test::find()->where(['id'=>1])-all(); 三.  [id>0]  选出id>0的数据 $results = Test::find()->where(['>','id',0])->all() 四.…
1.model中models/article.php 1 <?php 2 3 namespace app\models; 4 5 use Yii; 6 7 /** 8 * This is the model class for table "yii2_article". 9 * 10 * @property string $id 11 * @property integer $category_id 12 * @property string $title 13 * @prope…
1.控制器中CacheDemoController.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/06/29 * Time: 8:38 */ namespace app\controllers; use yii\web\Controller; class CacheDemoController extends Controller { /* public function behaviors() { return…
第一次使用,时候不明白什么原理,大概用了几次后,才模模糊糊搞清楚原来是怎么一回事,现在就把写过的代码,贴在下边. 1.在视图文件中, 第一步首先在index.php文件中 做了一个a链接的按钮 调用了modal <a class="btn btn-default pull-right" data-remote="<?= Url::toRoute(['create', '_wicket' => 'yes']) ?>" data-toggle=&…
1.Model中Code.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/07/25 * Time: 10:48 */ namespace app\models; use yii\base\Model; class Code extends Model{ public $verifyCode; public function rules() { return [ ['verifyCode','captcha','c…
1.创建model   /biaodan.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/08/05 * Time: 10:26 */ namespace app\models; use Yii; use yii\base\Model; class Biaodan extends Model{ public $name; public $pass; public $email; public $sex; publi…
1.在widgets/TestWidget.php中 <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/08/05 * Time: 18:15 */ namespace app\widgets; use yii\base\Widget; class TestWidget extends Widget { public $msg = ''; //初始化 public function init() { parent::init…
这是第一种方法,还有另一种方法,其实都差不多. 1.在创建widgets\HelloWiget.php <?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/08/05 * Time: 15:55 */ namespace app\widgets; use yii\base\Widget; class HelloWidget extends Widget { public $msg = ''; //初始化 publ…
在控制器中查询好数据  $model 在视图中输入 <?php foreach($model as $key=>$r):?> <tr class="text-center"> <td><?=$r->id?></td> <td><?=$r->name?></td> <td><?php echo Province::find()->where(['cou…
方法一: //判断签约状态 $signed = 0; $sql="SELECT * from usho_community_sign_record WHERE com_id=$r->id AND end_date = (SELECT MAX(end_date) AS Largest_End_date from usho_community_sign_record WHERE com_id=$r->id)"; $sign_model = Yii::$app->db-&g…