thinkphp 根据条件查数据库存在记录则修改 不存在则添加

thinkphp 根据条件查数据库存在记录则修改 不存在则添加,第1张

$rs = D("table")

if($rs->where(array("id"=>$id,"cid"=>$cid))->count()){

    //存在

    

}else{

    //不存在

    

}

1、从index页面最新动态链接到event页面,要想显示右边栏,最简单的方法就是将超链接直接指向event页面,就像导航栏“动态”一样

2、但是你需要传递最新动态的eventID,所以event()函数应该增加接收eventID的内容

3、另外,你显示页面默认显示数据的方法getContentBy2()可以删除,将其内容整合到event()函数中,参考第2点,如果接收到eventID,说明是通过index的最新动态链接过来的,没接收到eventID则是直接访问的

综上所述,我给出event()函数的大致内容

public function event(){

// ... 你原先的内容

// 以下新增内容

$eventID = I("eventID",0,"intval")// 读取eventID,不存在则默认为0

if($eventID){

// 存在,即从index的最新动态链接过来

// ... 你原先index控制器getContent()函数的内容,注意display()那行就不要了

} else {

// 不存在eventID,即直接访问的,那就显示默认内容

// 也就是你原先getContentBy2()函数的内容,注意不用ajax返回,采用assign()赋值即可

}

}

相应的,前台需要修改的有:

①index页面最新动态的超链接

②删除event页面getContentBy2()的js代码

解决方案:

在 \application\Common\Controller\目前添加“EmptyBaseController.class.php”文件

<?php/**

*@Author:HTL

*@Email:[email protected]

*@DateTime:2015-07-1411:22:18

*@Description:空模板控制器

*@use:其他项目添加EmptyController文件并继承该类即可

*/namespace Common\ControlleruseThink\Controllerclass EmptyBaseController extendsController{function_initialize(){//项目配置文件中的配置项

$emptyPath=C("EMPTY_PATH")//如果未配置默认的地址

if(!$emptyPath || empty($emptyPath))$emptyPath="/"header("Location:".$emptyPath)exit()

}

}

2.在所有项目的Controller目前里添加EmptyController.class.php并继承”\Common\Controller\EmptyBaseController“

<?php/**

*@Description:空模板控制器,直接继承\Common\Controller\EmptyBaseController即可

*/namespace Portal\Controllerclass EmptyControllerextends \Common\Controller\EmptyBaseController{

function _initialize(){

parent::_initialize()

}

}

3.在\data\conf\config.php里添加" EMPTY_PATH "项自定义当访问不存在的模块时需要跳转的页面

<?php return array('EMPTY_PATH'=>'/index.php',/*访问不存在的模块时跳转的地址*/

//其他配置项

)?

>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11898919.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存