yman
- yman 2015-06-12 已签到连续签到4天,获得了20个金钱
- yman 提出了问题yii 数据库迁移可以给字段设置注释吗
- yman 2015-06-11 已签到连续签到3天,获得了15个金钱
<?php $this->beginBody() ?> <?php echo $content;?> <?php $this->endBody() ?>
<?php $this->head() ?> <?php $this->beginPage() ?> <?php $this->endPage();?>
加上就有了
<?php
namespace app\backend\modules\applyadmin\controllers;
use Yii;
use yii\web\Controller;
use app\frontend\models\Apply;
use yii\data\Pagination;class DefaultController extends Controller
{function actionIndex(){ $query = Apply::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' =>$countQuery->count(),'pageSize' => '2']); $models = $query->offset($pages->offset) ->limit($pages->limit) ->OrderBy(['status'=>SORT_DESC]) ->all(); $this->render('index', [ 'models'=>$models, 'pages'=>$pages, ]); }
}
<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
use \yii\helpers\Markdown;
use \yii\helpers\Url;
?>
<?php foreach ($models as $val) :?>
<?php echo $val->id;?>
<?php endforeach; ?>
<?php// 显示分页
echo LinkPager::widget(['pagination' => $pages,
]);
?>为什么我的这样输出不了数据 在foreach 外面就能输出数据。
数据格式是
array(2) { [0]=> object(app\frontend\models\Apply)#35 (8) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(5) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(2) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(5) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(2) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(2) { ["beforeInsert"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } ["beforeUpdate"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } } ["_behaviors":"yii\base\Component":private]=> array(1) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } } } [1]=> object(app\frontend\models\Apply)#48 (8) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(2) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(1) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(2) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(1) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(2) { ["beforeInsert"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } ["beforeUpdate"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } } ["_behaviors":"yii\base\Component":private]=> array(1) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } } } }
是不是表有问题还是咋呢 一直纠结
不能截图啊。抱歉。主要是views 层有值缺不能遍历出来。我把分页方法封装好了就可以了
- yman 2015-06-10 已签到连续签到2天,获得了10个金钱
我把分页方法封装到基类里面 就能正常分页
/** * * @param pageSize:设置每页的大小 * @param order:数据的排序 * @param rows:返回的数组中数据对象的键名 * @param pages:返回的数组中分页对象的键名 * @return \yii\web\Pagination */ public function getPagedRows($query,$config=[]) { $countQuery = clone $query; $pages=new Pagination(['totalCount' => $countQuery->count()]); if(isset($config['pageSize'])) { $pages->setPageSize($config['pageSize'],true); } $rows = $query->offset($pages->offset)->limit($pages->limit); if(isset($config['order'])) { $rows = $rows->orderBy($config['order']); } $rows = $rows->all(); $rowsLable='rows'; $pagesLable='pages'; if(isset($config['rows'])) { $rowsLable=$config['rows']; } if(isset($config['pages'])) { $pagesLable=$config['pages']; } $ret=[]; $ret[$rowsLable]=$rows; $ret[$pagesLable]=$pages; return $ret; }
求指教
- yman 评论了教程 yii2.0 分页(二)
<?php
namespace app\backend\modules\applyadmin\controllers;
use Yii;
use yii\web\Controller;
use app\frontend\models\Apply;
use yii\data\Pagination;class DefaultController extends Controller
{function actionIndex(){ $query = Apply::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' =>$countQuery->count(),'pageSize' => '2']); $models = $query->offset($pages->offset) ->limit($pages->limit) ->OrderBy(['status'=>SORT_DESC]) ->all(); $this->render('index', [ 'models'=>$models, 'pages'=>$pages, ]); }
}
<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
use \yii\helpers\Markdown;
use \yii\helpers\Url;
?>
<?php foreach ($models as $val) :?>
<?php echo $val->id;?>
<?php endforeach; ?>
<?php// 显示分页
echo LinkPager::widget(['pagination' => $pages,
]);
?>为什么我的这样输出不了数据 在foreach 外面就能输出数据。
数据格式是
array(2) { [0]=> object(app\frontend\models\Apply)#35 (8) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(5) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(2) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(5) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(2) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(2) { ["beforeInsert"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } ["beforeUpdate"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } } ["_behaviors":"yii\base\Component":private]=> array(1) { [0]=> object(yii\behaviors\TimestampBehavior)#39 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } } } [1]=> object(app\frontend\models\Apply)#48 (8) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(2) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(1) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(2) ["uid"]=> string(1) "1" ["centent"]=> string(516) "a:20:{s:9:"is_people";s:1:"1";s:7:"company";s:11:"dsadsaddsad";s:7:"license";s:6:"dsadas";s:5:"legal";s:6:"dsadsa";s:6:"number";s:6:"dsadsa";s:8:"business";s:6:"dsadsa";s:7:"address";s:4:"dsad";s:5:"range";s:8:"dsadsdsa";s:4:"tell";s:6:"dsadsa";s:4:"name";s:6:"dsadsa";s:6:"iphone";s:9:"dsadsaads";s:11:"license_img";s:0:"";s:8:"code_img";s:0:"";s:9:"legal_img";s:0:"";s:5:"apply";s:0:"";s:10:"safety_img";s:0:"";s:12:"sanitary_img";s:0:"";s:8:"star_img";s:0:"";s:9:"plate_img";s:0:"";s:5:"agree";a:1:{i:0;s:1:"1";}}" ["is_people"]=> int(0) ["status"]=> int(1) ["created_at"]=> int(0) ["updated_at"]=> int(0) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(2) { ["beforeInsert"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } ["beforeUpdate"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } } ["_behaviors":"yii\base\Component":private]=> array(1) { [0]=> object(yii\behaviors\TimestampBehavior)#49 (5) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["owner"]=> RECURSION } } } }
是不是表有问题还是咋呢 一直纠结
- yman 2015-06-09 已签到连续签到1天,获得了5个金钱