當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。