1.php中彈框跳轉
echo "<script>alert('修改成功');location.href='pdo_show.php'</script>";
2.pdo鏈接
$dbh = new PDO("mysql:host=127.0.0.1;port=3306;dbname=test;charset=utf8", "root", "root");
3.pdo執行查詢
$dbh->query($sql)->fetchAll(PDO::FETCH_NUM);索引數組,數字下標
$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);關聯數組
4.jquery改變屬性 — attr()
$('#create_db').attr('href','?r=dbs/show_db&k='+k);
5.javascript阻止form表單提交:
οnsubmit="return checkSubmit();"
6. jquery動態創建的元素要用事件委託的方式綁定事件這是append追加上的元素:
$('#dbname').append("<a href='?r=index/tablenames&at_dbname='"+createdb+"''>刪除</a>");
要想追加上的a標籤的點擊事件依舊有效,就必須使用事件委託
剛開始
$(".dbnames").click(function(){ })
託後的:
$('#dbname').on("click", ".dbnames", function(){
7.禁用一個按鈕
<input id="btnShow" type="button" value="點擊" class="btn">
直接在input標籤上禁用
<input id="btnShow" type="button" disabled value="點擊" class="btn">
原生的js方式:
document.getElementByIdx_x_x("btnShow").disabled=true;
如果要重新開啓按鈕,則可以讓disabled=false;即可.
jQuery方式:
$("#btnShow").attr({"disabled":"disabled"});
如要讓按鈕恢復可用,可以採用removeAttr方法把disabled屬性刪除即可。$("#btnShow").removeAttr("disabled");
8.js獲取指定字符前後的內容
<script type="text/javascript">
/*
string 字符串;
str 指定字符;
split(),用於把一個字符串分割成字符串數組;
split(str)[0],讀取數組中索引爲0的值(第一個值),所有數組索引默認從0開始;
*/
function getStr(string,str){
var str_before = string.split(str)[0];
var str_after = string.split(str)[1];
alert('前:'+str_before+' - 後:'+str_after);
}
</script>
9.鼠標滑過變小手
cursor: pointer;
10.password_hash加密使用方法
加密:$hash = password_hash('要加密的字符', PASSWORD_DEFAULT);
驗證:password_verify('123456',$hash);
PASSWORD_DEFAULT是加密方式,還可以有第三個參數,是執行多少次,可以爲空。
11.修改yii2默認訪問控制器
D:\phpstudy\WWW\advanced\vendor\yiisoft\yii2\web\Application.php
12.關閉yii2自帶csrf驗證
public $enableCsrfValidation = false;
13.yii2獲取當前控制器和方法名
控制器:$controllerID = Yii::$app->controller->id;
方法名:$actionID = Yii::$app->controller->action->id;
14.yii2分頁
use yii\db\Query;
use yii\data\Pagination;
public function actionIndex(){
$query = new Query();
//取到數據的總條數
$count = $query->from('goods')->count();
$pagination = new Pagination(['totalCount' => $count,'pageSize' =>3]);
//每頁顯示的數據
$info = $query->select('*')
->from('goods')
->offset($pagination->offset)
->limit($pagination->limit)
->orderBy('id asc')
->all();
return $this->render('index', [
'page' => $pagination,
'goods' => $info
]);
}
V層頁面代碼:
<?php
use yii\widgets\Linkpager;
?>
<?= linkPager::widget([
'pagination' => $page,
])?>
15.yii框架構造函數
public function beforeaction($action){
}