Yii框架常见问题

FAQ Alan 7年前 (2017-05-04) 5597次浏览 0个评论 扫描二维码

Yii的MVC基础知识

basic版非常清晰,分别位于controllers, models, views文件夹下

controllers下的文件通常心Controller结尾,如IndexController.php, 需访问通常在类中添加actionXxx方法,如需通过?r=index/index方法,在IndexController类中添加actionIndex方法

models下的文件名通常与数据表名称一致

views下的目录名通常与控制器一致

1.Database Exception – yii\db\Exception

SQLSTATE[HY000] [2002] No such file or directory

本地开发时如出现这一错误,请尝试将config/db.php中的mysql:host= localhost修改成mysql:host=127.0.0.1

 

2.如何去除顶部默认的导航条?

Yii框架常见问题

// 方法一:在controller中加入
$this->layout = false; // 在类中加入可作用下其它的所有方法
// 方法二:将return $this->render('index')替换为如下代码
return $this->renderPartial('index');

3.No such file or directory in vendor/yiisoft/yii2/db/Connection.php at line 603

请检查common/config/main-local.php中配置文件host是否为localhost并尝试修改127.0.0.1进行连接

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址