当前位置: 首页>>代码示例>>PHP>>正文


PHP Topic::connection方法代码示例

本文整理汇总了PHP中Topic::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::connection方法的具体用法?PHP Topic::connection怎么用?PHP Topic::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Topic的用法示例。


在下文中一共展示了Topic::connection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Run Method.
  */
 public function run()
 {
     Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 0');
     $faker = Faker\Factory::create('ru_RU');
     // Заполнение разделов
     $data = [];
     for ($i = 0; $i < 15; $i++) {
         $data[] = ['sort' => $i, 'parent_id' => $i < 4 ? 0 : rand(1, 4), 'title' => $faker->realText(rand(20, 30)), 'description' => $faker->realText(rand(30, 50)), 'closed' => $i % 5 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Forum::connection()->query('TRUNCATE forums');
     $table = $this->table('forums');
     $table->insert($data)->save();
     // Заполнение тем
     $data = [];
     for ($i = 0; $i < 100; $i++) {
         $data[] = ['forum_id' => rand(1, 15), 'user_id' => rand(1, 5), 'title' => $faker->realText(rand(25, 50)), 'note' => $i % 3 ? $faker->realText(rand(30, 100)) : '', 'closed' => $i % 5 ? 0 : 1, 'locked' => $i % 6 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Topic::connection()->query('TRUNCATE topics');
     $table = $this->table('topics');
     $table->insert($data)->save();
     // Заполнение сообщений
     $data = [];
     for ($i = 0; $i < 1000; $i++) {
         $data[] = ['forum_id' => rand(1, 15), 'topic_id' => rand(1, 50), 'user_id' => rand(1, 5), 'text' => $faker->realText(rand(50, 500)), 'ip' => $faker->ipv4, 'brow' => App::getUserAgent($faker->userAgent), 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Post::connection()->query('TRUNCATE posts');
     $table = $this->table('posts');
     $table->insert($data)->save();
     Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 1');
 }
开发者ID:visavi,项目名称:rotorcms,代码行数:33,代码来源:ForumsSeeder.php

示例2: createTopic

 /**
  * Создание темы
  */
 public function createTopic()
 {
     if (Request::isMethod('post')) {
         $connection = Topic::connection();
         $connection->transaction();
         $topic = new Topic();
         $topic->token = Request::input('token', true);
         $topic->forum_id = Request::input('forum_id');
         $topic->title = Request::input('title');
         $topic->user_id = User::get('id');
         $topicSave = $topic->save();
         $post = new Post();
         $post->token = Request::input('token', true);
         $post->forum_id = Request::input('forum_id');
         $post->topic_id = $topic->id;
         $post->user_id = User::get('id');
         $post->text = Request::input('text');
         $post->ip = App::getClientIp();
         $post->brow = App::getUserAgent();
         if ($topicSave && $post->save()) {
             $post->topic->update_attribute('post_last_id', $post->id);
             $post->topic->forum->update_attribute('topic_last_id', $topic->id);
             $connection->commit();
             App::setFlash('success', 'Тема успешно создана!');
             App::redirect('/topic/' . $topic->id);
         } else {
             $connection->rollback();
             App::setFlash('danger', array_merge($post->getErrors(), $topic->getErrors()));
             App::setInput($_POST);
         }
     }
     $forums = Forum::getAll();
     App::view('forums.create', compact('forums'));
 }
开发者ID:visavi,项目名称:rotorcms,代码行数:37,代码来源:ForumController.php


注:本文中的Topic::connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。