thinkphp之要点知识

判断时候提交表单

request()->isPost()    如果没有提交返回值为空

获取提交过来的数据:

$data=input('post.')

用户的登录 将用户登录的信息进行保存*/

(1)页面按钮连接以及数据库的相关操作

增:不要的传入用户的id直接进行添加进入数据库里
    按钮:{:url('add')}    这里的add是指本函数里的一个方法

    数据库函数:$cater=db('cate')->insert($data);
    添加的时候会返回一个数值,就是影响行数


删:需要知道要删除的id,并进行数据以及信息的处理
    按钮:{:url('delete',array('id'=>$vo.id))}

    在delete方法中需要传入参数
    (public function delete($id))


    数据库函数:$link=Db::query("delete from article where id='$id'")
    这是用过发送mysql命令行的方式进行数据的删除
    Db::query函数



改:与删除相同:需要知道要删除的id,并进行相应信息的提取以及修改

    按钮:{:url('edit',array('id'=>$vo.id))}

    数据库函数:$line=db('article')->update($change);

(2)session
通过表单得到的管理员的信息进行存储:
session(‘id’,$admin[‘id’]);
session(‘password’,$admin[‘password’]);
session(‘name’,admin[‘name’]);

将登录的管理员信息进行提取
    $data=session('id');
    $data2=session('password');
    $data3=session('name');

管理员录出登录的操作:
    session(null);
    清空信息

引用模板文件并将数据传入生成新的网页

(1)、    /**
* 创建静态页面
* @access protected
* @htmlfile 生成的静态文件名称
* @htmlpath 生成的静态文件路径
* @param string $templateFile 指定要调用的模板文件
* 默认为空 由系统自动定位模板文件
* @return string
*
*/
protected function buildHtml($htmlfile = '', $htmlpath = '', $templateFile = '')
{
$content = $this->fetch($templateFile);
$htmlpath = !empty($htmlpath) ? $htmlpath : './appTemplate/';
$htmlfile = $htmlpath . $htmlfile . '.'.config('url_html_suffix');

$File = new \think\template\driver\File();
$File->write($htmlfile, $content);
return $content;
}

(2)、
$this->assign('data',$data);
$this->buildHtml('文件名','存放的位置','inde@index/news')   index控制器下index下的index方法

(3)、
    index/index.php里的index方法是
    public function news(){
        return view('news');
    }
Fork me on GitHub