发布后获取参考密钥

时间:2015-07-27 10:20:30

标签: php oop reference

创建帖子后,其post id是主键。如何获取此post id并将其发布到日期时间数据库表及其表的引用键

if (isset($_POST['submit'])) { 
        global $post;
        $post->user_id= $_SESSION['user_id'];
        $post->post_created_date = strip_zeros_from_date(date("Y-m-d"));
        $post->post_created_time = "int time ( void )";
        if ($post->createpost()){
            global $datetime;
            $datetime->post_id = ??? ;


            redirect_to('profile.php');
        } else {
            // Failure
            echo 'failed';
        }
    }

1 个答案:

答案 0 :(得分:0)

不知道您正在使用哪种技术,但假设createpost方法返回创建的帖子信息,您可以执行以下操作:

if ($newPost = $post->createpost()){
        global $datetime;
        $datetime->post_id = $newPost['id'];
        ...