Andremyid Post 包。

v0.1.0 2016-09-23 17:57 UTC

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 = $slug
  • Post::find($id); 获取 wp_posts,其中 id = $id
  • Post::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 = $id
  • Post::delete($id); 删除 wp_post,其中 id = $id

术语表

  • Term::model(); 调用新的 Model Term (wp_terms)
  • Term::findSlug('sample-slug') 返回查询结果中的数据,其中 wp_terms.name = $slug
  • Term::find($id); 获取 wp_terms,其中 term_id = $id
  • Term::create($data); 创建 wp_terms
  • Term::update($id); 更新 wp_terms,其中 id = $id
  • Term::delete($id); 删除 wp_terms,其中 id = $id

鸣谢

它受到 WordPress 的启发