1.controller控制中 $modelCountrytelCode = CountryTelCode::find()->orderBy('id DESC')->all(); $telCode = ArrayHelper::map($modelCountrytelCode,'area_code','name'); //显示name,传值area_code ***********其他代码************ return $this->render('createUser', […
方法一: <?php $psObjs = Poststatus::find()->all(); $allStatus = ArrayHelper::map($psObjs,'id','name'); ?> <?=$form->field($model,'status') ->dropDownList($allStatus, ['prompt'=>'请选择状态']); ?> 方法二: <?php $psArray = Yii::$app->db-&…
  一. [: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.在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…
第一次使用,时候不明白什么原理,大概用了几次后,才模模糊糊搞清楚原来是怎么一回事,现在就把写过的代码,贴在下边. 1.在视图文件中, 第一步首先在index.php文件中 做了一个a链接的按钮 调用了modal <a class="btn btn-default pull-right" data-remote="<?= Url::toRoute(['create', '_wicket' => 'yes']) ?>" data-toggle=&…
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.控制器中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.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.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…