andremyid / post
Andremyid Post 包。
v0.1.0
2016-09-23 17:57 UTC
Requires
- php: >=5.4.0
- andremyid/framework: 0.1.*
This package is not auto-updated.
Last update: 2024-09-24 21:06:14 UTC
README
Andremyid Post 包。
安装
- 将以下内容添加到您的
Composer JSON文件中
"andremyid/post": "~0.0"
- 运行 Composer
$ composer update
- 将以下内容添加到 'Andremyid/Framework-Core' => 'ServiceProvider'
Andremyid\Post\PostServiceProvider
- 运行迁移
您可以使用 WordPress 的数据库,或从示例数据库复制并手动迁移(您可以修改示例数据库)
// first, optional
$ composer dump-autoload
// and then
$ php andre migrate
使用方法
扩展
- 示例后端页面
<?php use Andremyid\Post\SampleBackendPage; use Andremyid\Post\BackendPageTrait; class YourControllerBackendName extends SampleBackendPage { use BackendPageTrait; public function post_index() { return $this->index(); // use sample backend page } // uncomment below to replace sample backend page // protected funtion index() // { // return $this->viewModule($this->module, "Title Backend Module"); // } }
- 示例前端页面
<?php use Andremyid\Post\SampleFrontendPage; use Andremyid\Post\FrontendPageTrait; class YourControllerFrontendName extends SampleFrontendPage { use FrontendPageTrait; public function post_index() { return $this->index(); // use sample frontend page } // uncomment below to replace sample frontend page // protected funtion index() // { // $post = Post::model()->ofPublish(); // return $this->view($this->themes . 'index' , $post); // } }
模型
帖子表
Post::model();调用新的 Model Post (wp_posts)Post::findSlug('sample-post-name')返回查询结果中的数组数据,其中wp_posts.post_name = $slugPost::find($id);获取wp_posts,其中id = $idPost::create($data);创建wp_posts
// sample create post manually Post::setCategory(array('uncategorized'); Post::setStatus('publish'); // auto-draft, inherit, publish Post::setType('post'); // default 'post' $data = array( 'post_author' => $user_id, 'post_content' => 'Sample Content', 'post_title' => 'Sample Title', 'post_name' => Post::makeSlug('Sample Title'), ); Post::create($data);
Post::update($id);更新wp_post,其中id = $idPost::delete($id);删除wp_post,其中id = $id
术语表
Term::model();调用新的 Model Term (wp_terms)Term::findSlug('sample-slug')返回查询结果中的数据,其中wp_terms.name = $slugTerm::find($id);获取wp_terms,其中term_id = $idTerm::create($data);创建wp_termsTerm::update($id);更新wp_terms,其中id = $idTerm::delete($id);删除wp_terms,其中id = $id
鸣谢
它受到 WordPress 的启发