本文整理汇总了PHP中Topic::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::create方法的具体用法?PHP Topic::create怎么用?PHP Topic::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave($options = array())
{
//parent::beforeSave($options);
//print_r($this->data);
$loggedInUser = AuthComponent::user();
$found = false;
$userId = $loggedInUser['user_id'];
$this->data['Post']['post_by'] = $userId;
$this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
//format('Y-m-d H:i:s')
if (!empty($this->data['Topic']['topic_subject'])) {
$str = $this->data['Topic']['topic_subject'];
$num = $this->data['Post']['post_cat'];
$subject = new Topic();
$found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
if (!$found) {
$subject->create();
//create topic
$subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
//see also save associated model method cakephp
$this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
return true;
}
$this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
return true;
}
//nothing
return true;
}
示例2: run
public function run()
{
$faker = Faker\Factory::create();
for ($i = 0; $i < 50; $i++) {
$new = Topic::create(array('author' => $faker->name, 'title' => $faker->sentence(10), 'message' => $faker->paragraphs(2, true), 'place' => $faker->randomElement(array('web', 'api')), 'updated_at' => $faker->dateTime('now'), 'created_at' => $faker->dateTime('now')));
}
}
示例3: handle_request
function handle_request()
{
# GET params
$topic_name = $_POST['topic_name'];
$topic_desc = $_POST['topic_desc'];
$resource_name = $_POST['resource_name'];
$resource_desc = $_POST['resource_desc'];
$resource_uri = $_POST['resource_uri'];
$resource_type = $_POST['resource_type'];
#echo($topic_name);
# PROCESS request
Topic::create($topic_name, $topic_desc, $resource_name, $resource_desc, $resource_uri, $resource_type);
header("location: list.php");
}
示例4: run
public function run()
{
$faker = Faker::create();
$users = User::lists('id');
$nodes = Node::lists('id');
foreach (range(1, 50) as $index) {
Topic::create(['user_id' => $faker->randomElement($users), 'node_id' => $faker->randomElement($nodes), 'title' => $faker->sentence(), 'body' => $faker->text(), 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
}
foreach (range(1, 50) as $index) {
Topic::create(['user_id' => $faker->randomElement($users), 'node_id' => $faker->randomElement($nodes), 'title' => $faker->sentence(), 'body' => $faker->text(), 'is_excellent' => true, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
}
foreach (range(1, 30) as $index) {
Topic::create(['user_id' => $faker->randomElement($users), 'node_id' => $faker->randomElement($nodes), 'title' => $faker->sentence(), 'body' => $faker->text(), 'is_wiki' => true, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
}
foreach (range(1, 100) as $index) {
Topic::create(['user_id' => 1, 'node_id' => $faker->randomElement($nodes), 'title' => $faker->sentence(), 'body' => $faker->text(), 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
}
}
示例5: transfer_topics_3_5
function transfer_topics_3_5($p_parentId = 0)
{
global $g_ado_db;
$sql = 'SELECT * FROM TopicsOld';
if (!is_null($p_parentId)) {
$sql .= " WHERE ParentId = {$p_parentId}";
}
$sql .= ' ORDER BY TopicOrder DESC, LanguageId ASC';
$rows = $g_ado_db->GetAll($sql);
foreach ($rows as $row) {
$topic = new Topic($row['Id']);
if ($topic->exists()) {
$topic->setName($row['LanguageId'], $row['Name']);
} else {
$topic->create(array('parent_id' => $p_parentId, 'names' => array($row['LanguageId'] => $row['Name'])));
transfer_topics_3_5($topic->getTopicId());
}
}
}
示例6: require_once
require_once(INCLUDE_DIR.'class.topic.php');
$do=strtolower($_POST['do']);
switch($do){
case 'update':
$topic = new Topic($_POST['topic_id']);
if($topic && $topic->getId()) {
if($topic->update($_POST,$errors))
$msg='Topic updated successfully';
elseif(!$errors['err'])
$errors['err']='Error updating the topic';
}else{
$errors['err']='Internal error';
}
break;
case 'create':
if(Topic::create($_POST,$errors))
$msg='Help topic created successfully';
elseif(!$errors['err'])
$errors['err']='Unable to create the topic. Internal error';
break;
case 'mass_process':
if(!$_POST['tids'] || !is_array($_POST['tids'])) {
$errors['err']='You must select at least one topic';
}else{
$count=count($_POST['tids']);
$ids=implode(',',$_POST['tids']);
if($_POST['enable']){
$sql='UPDATE '.TOPIC_TABLE.' SET isactive=1, updated=NOW() WHERE topic_id IN ('.$ids.') AND isactive=0 ';
if(db_query($sql) && ($num=db_affected_rows()))
$msg="$num of $count selected services enabled";
else
示例7: array
$errorMsgs = array();
if (empty($f_topic_name)) {
$correct = false;
$errorMsgs[] = getGS('You must fill in the $1 field.','<B>'.getGS('Name').'</B>');
}
if ($f_topic_language_id <= 0) {
$correct = false;
$errorMsgs[] = getGS('You must choose a language for the topic.');
}
if (!empty($f_topic_name)) {
if ($f_topic_id == 0) {
// Create new topic
$topic = new Topic();
$created = $topic->create(array('parent_id' => $f_topic_parent_id,
'names'=>array($f_topic_language_id=>$f_topic_name)));
} else {
// Translate existing topic
$topic = new Topic($f_topic_id);
$created = $topic->setName($f_topic_language_id, $f_topic_name);
}
if ($created) {
camp_html_goto_page("/$ADMIN/topics/index.php");
} else {
$errorMsgs[] = getGS('The topic name is already in use by another topic.');
}
} else {
$errorMsgs[] = getGS('You must fill in the $1 field.','<B>'.getGS('Name').'</B>');
}
$crumbs = array();
示例8: sprintf
if ($_REQUEST['id'] && !($topic = Topic::lookup($_REQUEST['id']))) {
$errors['err'] = sprintf(__('%s: Unknown or invalid ID.'), __('help topic'));
}
if ($_POST) {
switch (strtolower($_POST['do'])) {
case 'update':
if (!$topic) {
$errors['err'] = sprintf(__('%s: Unknown or invalid'), __('help topic'));
} elseif ($topic->update($_POST, $errors)) {
$msg = sprintf(__('Successfully updated %s'), __('this help topic'));
} elseif (!$errors['err']) {
$errors['err'] = sprintf(__('Error updating %s. Try again!'), __('this help topic'));
}
break;
case 'create':
if ($id = Topic::create($_POST, $errors)) {
$msg = sprintf(__('Successfully added %s'), Format::htmlchars($_POST['topic']));
$_REQUEST['a'] = null;
} elseif (!$errors['err']) {
$errors['err'] = sprintf(__('Unable to add %s. Correct error(s) below and try again.'), __('this help topic'));
}
break;
case 'mass_process':
switch (strtolower($_POST['a'])) {
case 'sort':
// Pass
break;
default:
if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
$errors['err'] = sprintf(__('You must select at least %s'), __('one help topic'));
}
示例9: Topic
<?php
//Create Topic Object
$topic = new Topic();
if (isset($_POST['do_create'])) {
//Create Validator Object
$validate = new Validator();
//Create Data Array
$data = array();
$data['title'] = $_POST['title'];
$data['body'] = $_POST['body'];
$data['category_id'] = $_POST['category'];
$data['user_id'] = getUser()['user_id'];
$data['last_activity'] = date("Y-m-d H:i:s");
//Required Fields
$field_array = array('title', 'body', 'category');
if ($validate->isRequired($field_array)) {
//Register User
if ($topic->create($data)) {
redirect('index.php', 'Your topic has been posted', 'success');
} else {
redirect('topic.php?id=' . $topic_id, 'Something went wrong with your post', 'error');
}
} else {
redirect('create.php', 'Please fill in all required fields', 'error');
}
}
//Get Template & Assign Vars
$template = new Template('templates/create.php');
//Assign Vars
//Display template
echo $template;
示例10: run
public function run()
{
Topic::create(['user_id' => 1, 'title' => '戏剧人生,人生戏剧', 'content' => '戏剧的道路很长很长,多久才能走完,我曾经这样的问我,路在何方,在何方,其实没有荆棘的道路该有多凄凉']);
Topic::create(['user_id' => 2, 'title' => '戏剧人生,人生戏剧', 'content' => '戏剧的道路很长很长,多久才能走完,我曾经这样的问我,路在何方,在何方,其实没有荆棘的道路该有多凄凉']);
}
示例11: createAndTest
private function createAndTest($p_topicId, $p_data, $p_left, $p_right)
{
$topic = new Topic($p_topicId);
$topic->create($p_data);
unset($topic);
$topic = new Topic($p_topicId);
$this->assertTrue($topic->exists());
foreach ($p_data['names'] as $languageId=>$name) {
$this->assertEquals($name, $topic->getName($languageId));
}
$this->assertEquals($p_left, $topic->getLeft());
$this->assertEquals($p_right, $topic->getRight());
}
示例12: run
public function run()
{
$i = 0;
for ($i == 0; $i < 50; $i++) {
Topic::create(['title' => '这里是主题主题' . $i, 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。', 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg', 'scan_num' => rand(1111, 4444), 'focus_num' => rand(1111, 8888)]);
}
// Topic::create([
// 'title'=>'这里是主题主题1',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题2',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题3',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题4',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题5',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题6',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题7',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题8',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题9',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题10',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题11',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
// Topic::create([
// 'title'=>'这里是主题主题12',
// 'content' => '安装完 Laravel 之后,首先需要做的事情就是为你的应用程序设置一个随机字符串作为整个应用的 key(用于加密)。如果你是通过 Composer 安装的 Laravel,这个 key 可能已经通过 key:generate 指令自动为你设置好了。',
// 'topic_url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/100kuai0-01.jpg',
// 'scan_num' => '19289',
// 'focus_num' => '2828'
// ]);
}
示例13: add
/**
* Create a new topic staticaly .
*
* The values array may have the following keys:
* - parent_id - parent topic identifier
* - node_left
* - node_right
* - names - array of topic translations of the form: language_id => name
*
* @param array $p_values
* @return json object
*/
public static function add($p_values = null)
{
$return = array();
$created = false;
if (!is_array($p_values)) {
$p_values = array();
}
$noName = FALSE;
if (!array_key_exists('f_topic_name', $p_values)) {
$noName = TRUE;
} else {
if (strlen($p_values['f_topic_name']) == 0) {
$noName = TRUE;
}
}
if ($noName) {
$return['status'] = 0;
$return['messageClass'] = 'error';
$return['message'] = getGS('You must fill in the $1 field.', '<B>' . getGS('Name') . '</B>');
} else {
$f_topic_parent_id = array_key_exists('f_topic_parent_id', $p_values) ? $p_values['f_topic_parent_id'] : 0;
$f_topic_language_id = array_key_exists('f_language_selected', $p_values) ? $p_values['f_language_selected'] : 1;
$f_topic_name = trim($p_values['f_topic_name']);
$topicParent = new Topic($f_topic_parent_id);
$topic = new Topic();
$created = $topic->create(array('parent_id' => $f_topic_parent_id, 'names' => array($f_topic_language_id => $f_topic_name)));
if ($created) {
$return['status'] = 1;
$return['messageClass'] = 'highlight';
$return['message'] = getGS('Topic created');
} else {
$return['status'] = 0;
$return['messageClass'] = 'error';
$return['message'] = getGS('The topic name is already in use by another topic.');
}
}
return json_encode($return);
}
示例14: run
public function run()
{
DB::table('topics')->delete();
Topic::create(array('title' => 'How to use Chatterr', 'content' => 'Welcome to Chatterr, we hope you enjoy your stay', 'user_id' => 1, 'category_id' => 1));
Topic::create(array('title' => 'Why Doge Is The Greatest Thing Ever', 'content' => 'We like dogs, but so do you. Go Doge!', 'user_id' => 1, 'category_id' => 2));
}