m_Orchestrate learning system---二十一、怎样写算法比较轻松
一、总结
一句话总结:(1、写出算法步骤,这样非常有利于理清思路,这样就非常简单了 2、把问题分细,小问题用函数弄出来)
1、学生端文章列表的格式是怎样的?
普通文章列表
这些样式的整体格式都是ul包li的形式
1、普通文章列表
就是一个am-list的经典样式:用了很多am-list的样式
1 <ul class="am-list"> //1、外层的ul是包裹整个list的,用的是amaze的列表am-list 2 <!--缩略图在标题右边--> 3 <li //每一个项 4 class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-right pet_list_one_block"> //2、am-g表示行a,网格布局 5 <div class="pet_list_one_info"> //3、顶部的那一行 6 <div class="pet_list_one_info_l"> 7 <div class="pet_list_one_info_ico"> 8 <img src="__STUDENT__/img/a1.png" alt=""> 9 </div> 10 <div class="pet_list_one_info_name">Super invincible 菁 11 </div> 12 </div> 13 <div class="pet_list_one_info_r"> 14 <div class="pet_list_tag pet_list_tag_xxs">新鲜事</div> 15 </div> 16 </div> 17 <div class=" am-u-sm-8 am-list-main pet_list_one_nr"> //4、这里是网格模式,左8右4 18 <h3 class="am-list-item-hd pet_list_one_bt"> //5、这里h3标签做标题,用的还是am-list-item-hd 19 <a href="###" class="">十一长假哪也不去,宅在家里看电影!</a> 20 </h3> //6、下面用的am-list-item-text 21 <div class="am-list-item-text pet_list_one_text">每逢长假,总有那么一群人选择远离人山人海,静静地呆在家,坐在电脑电视前。长时间的工作学习让他们感觉很疲惫,对什么都提不起劲,打开电脑却不知道干什么好…</div> 22 23 </div> 24 <div class="am-u-sm-4 am-list-thumb"> //7、这是右边的图片,还用了am-list-thumb 25 <a href="###" class=""> <img src="__STUDENT__/img/q1.jpg" 26 class="pet_list_one_img" alt="" /> 27 </a> //8、a标签包image的经典形式 28 </div> 29 </li> 30 </ul>
2、学生端多图配合文的形式如何实现?
这里的样式是:
div
顶部一行
/div
div
标题:h3
图片:ul包li的均分网格模式
简介:am-list-item-text,很普通的样式
/div
1 <li class="am-g am-list-item-desced pet_list_one_block"> 2 <div class="pet_list_one_info"> 3 <div class="pet_list_one_info_l"> 4 <div class="pet_list_one_info_ico"> 5 <img src="__STUDENT__/img/a3.png" alt=""> 6 </div> 7 <div class="pet_list_one_info_name">养了猫的飞飞</div> 8 </div> 9 <div class="pet_list_one_info_r"> 10 <div class="pet_list_tag pet_list_tag_stj">阅读</div> 11 </div> 12 </div> 13 <div class=" am-list-main"> 14 <h3 class="am-list-item-hd pet_list_one_bt"> 15 <a href="###" class="">浣熊孤儿掉到树下,被一家人收养之后……</a> 16 </h3> 17 <ul data-am-widget="gallery" 18 class="am-gallery am-avg-sm-3 19 am-avg-md-3 am-avg-lg-3 am-gallery-default pet_list_one_list"> 20 <li> 21 <div class="am-gallery-item"> 22 <a href="###" class=""> <img 23 src="__STUDENT__/img/qq1.jpg" alt="某天 也许会相遇 相遇在这个好地方" /> 24 </a> 25 </div> 26 </li> 27 <li> 28 <div class="am-gallery-item"> 29 <a href="###" class=""> <img 30 src="__STUDENT__/img/qq2.jpg" alt="不要太担心 只因为我相信" /> 31 </a> 32 </div> 33 </li> 34 <li> 35 <div class="am-gallery-item"> 36 <a href="###" class=""> <img 37 src="__STUDENT__/img/qq3.jpg" alt="终会走过这条遥远的道路" /> 38 </a> 39 </div> 40 </li> 41 </ul> 42 <div class="am-list-item-text pet_list_two_text">巴哈马拿骚的居民Rosie 43 Kemp发现一个刚出生的浣熊,掉在了树下。因为找不到小浣熊的妈妈了,Rosie和她的女儿Laura 44 Young决定收养这只小东西,并给她取名“小南瓜”。</div> 45 </div> 46 </li>
3、学生端的图片列表如何实现?
信息栏div+图片div(均分网格)
这里图片集用的是am-gallery
1 <li class="am-g am-list-item-desced pet_list_one_block"> 2 <div class="pet_list_one_info"> 3 <div class="pet_list_one_info_tytj"> 4 <i 5 class="iconfont pet_nav_kantuya pet_more_list_block_line_ico pet_list_tytj_ico"></i>诺奖得主回忆通知获奖那一刻 6 </div> 7 <div class="pet_list_one_info_r"> 8 <div class="pet_list_tag pet_list_tag_kty">图集</div> 9 </div> 10 </div> 11 <div class=" am-list-main"> 12 <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3 am-avg-md-3 am-avg-lg-3 am-gallery-default pet_list_one_list pet_list_one_tytj"> 13 <li> 14 <div class="am-gallery-item"> 15 <a href="###" class=""> <img 16 src="__STUDENT__/img/w1.jpg" alt="某天 也许会相遇 相遇在这个好地方" /> 17 </a> 18 </div> 19 </li> 20 <li> 21 <div class="am-gallery-item"> 22 <a href="###" class=""> <img 23 src="__STUDENT__/img/w2.jpg" alt="不要太担心 只因为我相信" /> 24 </a> 25 </div> 26 </li> 27 <li> 28 <div class="am-gallery-item"> 29 <a href="###" class=""> <img 30 src="__STUDENT__/img/w3.jpg" alt="终会走过这条遥远的道路" /> 31 </a> 32 </div> 33 </li> 34 <li> 35 <div class="am-gallery-item"> 36 <a href="###" class=""> <img 37 src="__STUDENT__/img/w4.jpg" alt="终会走过这条遥远的道路" /> 38 </a> 39 </div> 40 </li> 41 <li> 42 <div class="am-gallery-item"> 43 <a href="###" class=""> <img 44 src="__STUDENT__/img/w5.jpg" alt="终会走过这条遥远的道路" /> 45 </a> 46 </div> 47 </li> 48 <li> 49 <div class="am-gallery-item"> 50 <a href="###" class=""> <img 51 src="__STUDENT__/img/w6.jpg" alt="终会走过这条遥远的道路" /> 52 </a> 53 </div> 54 </li> 55 </ul> 56 </div> 57 </li>
4、Declaration of app\student\model\Engage::getData() should be compatible with think\Model::getData($name = NULL)?
自定义的函数和系统函数重名了
campatible是兼容的意思
5、如何在一个模型的模型外和模型里面获取数据?
模型外和模型里面获取数据(模型外要实例化模型对象,模型里面自然只需要$this即可)
参考手册模型外获取数据
$user = new User();
// 查询单个数据
$user->where('name', 'thinkphp')->find();
那模型里面肯定只需要使用$this对象即可啊
$res=$this->save($data);
6、thinkphp里面数据库表的拼接如何实现?
模型中用的一个长的sql
$article=db('article')->alias('a')->field('a.*,t.name as topicname,u.uname as authorname,u.picture as authorpicture')->join('topic t','a.topicid=t.id')->join('user u','a.authorid=u.id')->where('topicid','=',$v)->limit($artPerTopic)->order('click desc')->select();
join连了两个表
取出来的数据记得排序
7、如何快速高效的解决问题--对不同用户显示不同的数据?
解决问题思路的两条策略(对不同用户显示不同的数据)
1、把问题分细,小问题用函数弄出来
2、写出算法步骤,这样非常有利于理清思路
WeEngage中的模型
1 <?php
2 namespace app\student\model;
3
4 use think\Model; 5 class Engage extends Model 6 { 7 //返回显示到页面的数据 8 public function getData_(){ 9 //1、获取用户的id信息 10 $id=session('id'); 11 //2、获取用户的小组信息 12 $group=db('user')->field('ugid')->find($id); 13 //3、获取用户小组对应的topic信息(注意未分组成员的信息) 14 $ugid=$group['ugid']; 15 $topicID=-1; 16 $haveTopic=false;//表示选择了小组,小组也选了topic 17 if($ugid){ 18 $topicID=db('grouptopic')->where('gtgid','=',$ugid)->field('gttid')->select(); 19 if($topicID) { $haveTopic=true; } 20 //dump($topicID);die; 21 } 22 //如果学生没有选择分组或者分的组没有选择topic 23 if(!$topicID||$topicID==-1) $topicID=db('topic')->field('id')->select(); 24 $topics = array(); 25 //如果小组选择了话题 26 if($topicID){ 27 foreach ($topicID as $k => $v) { 28 29 if($haveTopic) $topics[]=$v['gttid']; 30 else $topics[]=$v['id']; 31 } 32 $topics=array_unique($topics); 33 sort($topics); 34 } 35 //4、获取topic信息下的文章,如果只有一个topic,那选10篇,2个topic,每个选6篇,3个每个选四篇,四个每个选3篇,五个每个选3,6个每个选2,七个每个选2,八个每个选2,9个每个选2,十个每个选1,超过10以上,每个选1 36 $artPerTopicArr=array(0,10,6,4,3,3,2,2,2,2,2);//每个topic选择的文章的数目 37 $topicNum=count($topics);//已选主题下的topic数目 38 $artPerTopic=1;//每个topic选择的文章的数目 39 if($artPerTopicArr[$topicNum]){ $artPerTopic=$artPerTopicArr[$topicNum];} 40 $articleArr=array();//文章集合 41 //遍历每个topic,然后找$artPerTopic篇这个topic下的文章 42 foreach ($topics as $k => $v) { 43 //dump($v); 44 $article=db('article')->alias('a')->field('a.*,t.name as topicname,u.uname as authorname,u.picture as authorpicture')->join('topic t','a.topicid=t.id')->join('user u','a.authorid=u.id')->where('topicid','=',$v)->limit($artPerTopic)->order('click desc')->select(); 45 $articleArr=array_merge($articleArr,$article); 46 //dump($article); 47 } 48 //dump($articleArr);die; 49 50 //5、将文章信息返回到页面 51 return $articleArr; 52 //这个算法还是会导致就是学生选了小组,小组选了topic,但是如果主题下面没有文章的话,还是没有文章 53 } 54 55 //得到所有topic下面的文章 56 public function getAllTopicAirticle(){ 57 58 } 59 60 61 //1、把问题分细,小问题用函数弄出来 62 //2、写出算法步骤,这样非常有利于理清思路,这样就非常简单了 63 }
8、WeEngage页面对不同用户返回不同数据,并且始终有数据返回的算法是什么?
WeEngage页面对不同用户返回不同数据,并且始终有数据返回算法
//engage正常的返回给页面数据的逻辑如下
//1、对于可以从用户->小组->topic->article可以取出非0的article的,就取article
//2、否则的话就直接在所有topic对应的article里面拿
这样就很清晰很简单了
9、组件化开发的好处是什么(或者说板块分离)?
a、简化开发
b、重复利用
c、代码少
d、结构清晰
想板块,板块分离
精彩评论板块
猜你喜欢板块
二、内容在总结中