lu_2015
- lu_2015 赞了评论
这么多人学习yii2,但是都不认为这是坑,这说明这不是坑,而是一种理解。
yii2是一个框架,这是真正的yii2,而yii2 advanced是在yii2框架上面做的一个通用的使用方式,虽然这个也是官方出品,但是,你完全可以不用他的frontend backend common,自己来组织文件结构。
现在回答你的问题, app代表命名空间的开始部分,在yii2 advanced 模板中的common\config\bootstrap.php文件中,你应该可以看到:<?php Yii::setAlias('common', dirname(__DIR__)); Yii::setAlias('frontend', dirname(dirname(__DIR__)) . '/frontend'); Yii::setAlias('backend', dirname(dirname(__DIR__)) . '/backend'); Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console'); Yii::setAlias('myapp', dirname(dirname(__DIR__)) . '/myapp');
譬如下面的myapp 是我自己定义的一个别名,那么你上面的代码,我需要改成:
namespace myapp\models; use myapp\models\Country;
所以这不是一个坑,app是一个代表,你放到哪个包下面,这个app就代表哪个包。
yii2还是很不错的,对新手是有点上手难一点,不光新手,就是毕业3年的程序员,也得用上半年左右,才能摸清,不是因为这个东西有多难,而是因为yii2封装的东西比较多,看完文档,在使用,都有一个过程。不过也有很多人在用yii2,但是只是用其中的一部分功能。呵呵、 - lu_2015 2016-01-29 已签到连续签到1天,获得了5个金钱
- lu_2015 赞了评论
这是我用的
/** * 字符截取 支持UTF8/GBK * @param $string * @param $length * @param $dot */ function str_cut($string, $length, $dot = '...') { $CHARSET = Yii::app()->charset; $strlen = strlen($string); if($strlen <= $length) return $string; $string = str_replace(array(' ',' ', '&', '"', ''', '“', '”', '—', '<', '>', '·', '…'), array(' ',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string); $strcut = ''; if(strtolower($CHARSET) == 'utf-8') { $length = intval($length-strlen($dot)-$length/3); $n = $tn = $noc = 0; while($n < strlen($string)) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n++; $noc++; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t <= 239) { $tn = 3; $n += 3; $noc += 2; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if($noc >= $length) { break; } } if($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&', '"', ''', '“', '”', '—', '<', '>', '·', '…'), $strcut); } else { $dotlen = strlen($dot); $maxi = $length - $dotlen - 1; $current_str = ''; $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵'); $replace_arr = array('&',' ', '"', ''', '“', '”', '—', '<', '>', '·', '…',' '); $search_flip = array_flip($search_arr); for ($i = 0; $i < $maxi; $i++) { $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; if (in_array($current_str, $search_arr)) { $key = $search_flip[$current_str]; $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str); } $strcut .= $current_str; } } return $strcut.$dot; }
- lu_2015 收藏了问题Yii2 的 Redis 操作问题
- lu_2015 赞了回答
@YiiSoEasy 这样做是很不妥的,yii的优势之一就是"惰性加载",这样做就是完全摒弃了这种优势。并且破坏封装,没有逼格。
- lu_2015 收藏了问题Yii2 如何输出 SQL 语句?