post
The Andremyid Post package.
Installation
- Add the following to your
Composer JSON
file
"andremyid/post": "~0.0"
- Run Composer
$ composer update
- Add the following to 'Andremyid/Framework-Core' => 'ServiceProvider'
Andremyid\Post\PostServiceProvider
- Run the migration
You can use database from WordPress, or copy from sample database migrate manually (you can modify as you like of the sample)
// first, optional
$ composer dump-autoload
// and then
$ php andre migrate
Usage
Extending
- Sample Backend Page
<?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");
// }
}
- Sample Frontend Page
<?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);
// }
}
Model
Posts Table
-
Post::model();
to call back new Model Post (wp_posts
) -
Post::findSlug('sample-post-name')
return array data from query wherewp_posts.post_name = $slug
-
Post::find($id);
to getwp_posts
whereid = $id
-
Post::create($data);
to createwp_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);
to updatewp_post
whereid = $id
-
Post::delete($id);
to deletewp_post
whereid = $id
Terms Table
-
Term::model();
to call back new Model Term (wp_terms
) -
Term::findSlug('sample-slug')
return data from query wherewp_terms.name = $slug
-
Term::find($id);
to getwp_terms
whereterm_id = $id
-
Term::create($data);
to createwp_terms
-
Term::update($id);
to updatewp_terms
whereid = $id
-
Term::delete($id);
to deletewp_terms
whereid = $id
Credits
It's inspired by WordPress