Through learning the ThinkCMF framework, this time the content is under the module that comes with the framework, under Portal
We know that the background editing article corresponds to the add.html below AdminPost
First of all Let’s change the add.html interface
First of all, we need to understand how its form submission and jump are set up
The way is action="{:u ('AdminPost/add_post')}"
or: href="{:U('AdminPost/index')}"
or: href="{:U('AdminPost/add' ,array('term'=>empty($term['term_id'])?'':$term['term_id']))}"
We know from the previous study of the ThinkCMF framework structure that the corresponding The add_post method must be defined in AdminPostController.class.php under the controller of the application
Of course the module should be under Portal. This is submitted by the form, that is, each input box in the form, Everything in the rich text editor is submitted to this method for processing
I have now created a new table, which is specifically used to store the various sources of articles
The corresponding database is like this, of course the database foreign key Ignore everything for now, because at the moment I am just learning and do not need to record who posted this article and other userids.
CREATE TABLE `zhuanti`(
id int unsigned not null primary key auto_increment COMMENT 'number',
type enum('travel','hotel','food') not null default 'travel' COMMENT 'type',
title varchar(35) not null default '' COMMENT 'title',
recommended tinyint not null default '0' COMMENT 'recommended',
istop tinyint not null default '0' COMMENT 'top',
pubdate varchar(50) not null default '0' COMMENT 'publish time',
keywords varchar(50) not null default '' COMMENT 'Keywords',
com_source varchar(50) not null default '' COMMENT 'Institution source',
zhuanti_content varchar(250) not null default '' COMMENT 'Special content',
imgsrc varchar(500) not null default '' COMMENT 'Picture address',
picdomain varchar(500) not null default '' COMMENT 'Prefixed picture address'
)engine=MyISAM DEFAULT CHARSET=UTF8;
The corresponding interface for publishing articles in the background is as follows:
Because my purpose is very clear, that is, as long as the rich text is in the editor, programming is pure HTML page, and what is passed to the android segment is an html address, which is opened with webview,
so other things in it can be ignored,
and then remove the verification of ThinkCMF. Is that thing still there? There is research, as long as this form is enough
The next step is to rewrite the add_post method
<span style="font-size:18px;"><strong> public function add_post(){ if (IS_POST) { $data['pubdate'] = $_POST['post']['pubdate']; $data['istop'] = $_POST['post']['istop']; $data['recommended'] = $_POST['post']['recommended']; $data['title'] = $_POST['post']['title']; $data['keywords'] = $_POST['post']['keywords']; $data['com_source'] = $_POST['post']['com_source']; $data['zhuanti_content'] = $this->getHTMLurl(); $data['type'] = $_POST['type'][0]; $data['imgsrc'] = implode('|',$_POST['photos_url']); $m = M('Zhuanti'); if($id = $m->data($data)->add()){ // insert into zhuanti (bupdate,istop...)values(值); $this->success('添加成功'); exit(); } $this->error('添加失败 : '.$m->getError()); } }</strong></span>
$data['zhuanti_content'] = $this-> ;getHTMLurl(); What is returned in this is the html address corresponding to the content
$data['imgsrc'] = implode('|',$_POST['photos_url']); This is to put multiple pictures In a string
The custom method is as follows
<span style="font-size:18px;"><strong> private function getHTMLurl(){ $content = $_POST['post']['content']; $src = './tpl/html/'.time().'.html'; file_put_contents($src, $content); return $src; }</strong></span>
What does this mean? First get the content, then generate the corresponding html address, and add the time guarantee The only thing is actually simple here, it still needs to be optimized
and then generate html
<span style="font-size:18px;"><strong> file_put_contents($src, $content);</strong></span>
<span style="font-size:18px;"><strong> </strong></span>
<span style="font-size:18px;"><strong>到这里还没有结束,是会报错的,因为html是需要前台显示的,也就是那个html是见在tpl下面的,那么在application的控制器里面必须要建立一个控制器了</strong></span>
<span style="font-size:18px;"><strong> </strong></span>
<span style="font-size:18px;"><strong><?php namespace Portal\Controller; use Common\Controller\HomeBaseController; class PostController extends HomeBaseController{ public function getHTML(){//这里随便取个什么名字的,无所谓, </strong></span>
<span style="font-size:18px;"><strong>}</strong></span>
<span style="font-size:18px;"><strong>}</strong></span>
<span style="font-size:18px;"><strong> </strong></span>
<span style="font-size:18px;"><strong>就这样结束了,然后是后台接口的编写了,这里先不介绍了</strong></span>
Copyright statement: This article is the original article of the blogger and may not be reproduced without the permission of the blogger.
The above introduces PHP learning---how to generate html from the content in the rich text editor and send it back to the android client, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.