教程开始
1.前期准备,想好自己要添加怎样的字段和表单类型,比如我想添加一个select表单,额外显示文章的状态,字段名称state,字段类型为int。
2.那么,打开phpmyadmin,首先在数据中新建名为state的字段,类型为int,允许为空,默认值为0
3.然后,准备好html代码,按照typecho原有的格式
<section class="typecho-post-option">
<label for="token-input-tags" class="typecho-label"><?php _e('审核状态'); ?></label>
<p>
<select id="state" name="state">
<option value="0" >审核中</option>
<option value="1" >不通过</option>
<option value="2" >审核通过?></option>
<option value="3" >已结算</option>
</select>
</p>
</section>
4.接下来,就要开始修改Widget文件。
首先是要让表单的提交接收一个新的参数,具体的文件在/var/Widget/Contents/Post/Edit.php
找到大概719行的位置,将在如下代码后新增加 'state'
$contents = $this->request->from('password', 'allowComment',
'allowPing', 'allowFeed', 'slug', 'tags', 'text', 'visibility', 'state');
5.控制文章增删改查的文件是/var/Widget/Abstract/Contents.php
大概257行,将在下面的代码新增加'table.contents.state'
return $this->db->select('table.contents.cid', 'table.contents.title', 'table.contents.slug', 'table.contents.created', 'table.contents.authorId',
'table.contents.modified', 'table.contents.type', 'table.contents.status', 'table.contents.text', 'table.contents.commentsNum', 'table.contents.order',
'table.contents.template', 'table.contents.password', 'table.contents.allowComment', 'table.contents.allowPing', 'table.contents.allowFeed',
'table.contents.parent','table.contents.state')->from('table.contents');
6.大概288行,插入内容字段定义的地方,增加如下代码(记得给前面的加上逗号,防止代码报错)
'state' => empty($content['state']) ? 0 : intval($content['state'])
7.大概333行,更新内容字段定义的地方,增加如下代码
'state' => empty($content['state']) ? 0 : intval($content['state'])
8.完成字段定义后,就可以将html放进文章的发布文件了。不过在这之前要修改一下,比如改为如下:
<section class="typecho-post-option">
<label for="token-input-tags" class="typecho-label"><?php _e('审核状态'); ?></label>
<p>
<select id="state" name="state">
<option value="0" <?php if ($post->state == 0): ?> selected<?php endif; ?>><?php _e('审核中'); ?></option>
<option value="1" <?php if ($post->state == 1): ?> selected<?php endif; ?>><?php _e('不通过'); ?></option>
<option value="2" <?php if ($post->state == 2): ?> selected<?php endif; ?>><?php _e('审核通过'); ?></option>
<option value="3" <?php if ($post->state == 3): ?> selected<?php endif; ?>><?php _e('已结算'); ?></option>
</select>
</p>
</section>
9.因为我要的是select表单,所以要根据$post->state的值来判断是否选择,那么其实如果要在其它地方将值调用出来,或者就是子级要用其它表单来调用值,用以下代码就好了
<?php $post->state(); ?>
10.保存之后,测试发布以下,确认没有报错,并且可以调出选中的select,就代表增加成了。
You can definitely see your skills in the article you write. The sector hopes for more passionate writers like you who are not afraid to say how they believe. At all times go after your heart.
This is my first time pay a quick visit at here and i am really pleassant to read everthing at alone place.
能下吗?找了几个不是云盘就是下载不了的
dsadsads
欢迎加入 Typecho 大家族