-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's wrong in repeat loop? #7
Labels
Comments
Well it looks to me, that your |
This is my page model <?php
namespace Model;
class Page extends Base {
// data configuration
protected
$fieldConf = array(
'title' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR256,
'nullable'=>false,
'required'=>true,
),
'slug' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR256,
'nullable'=>false,
'required' => true,
),
'image' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR256,
),
'teaser' => array(
'type' => \DB\SQL\Schema::DT_TEXT,
),
'text' => array(
'type' => \DB\SQL\Schema::DT_TEXT,
'required' => true,
),
'publish_date' => array(
'type' => \DB\SQL\Schema::DT_DATE
),
'published' => array(
'type' => \DB\SQL\Schema::DT_BOOLEAN,
'default'=>false,
),
'author' => array(
'belongs-to-one' => '\Model\User',
),
'show_in_menu' => array(
'type' => \DB\SQL\Schema::DT_BOOLEAN,
'default'=>true,
),
'parent_id' => array(
'belongs-to-one' => '\Model\Page',
),
'ordering' => array(
'type' => \DB\SQL\Schema::DT_INT,
'default'=>true,
),
),
$table = 'pages',
$db = 'DB';
/**
* magic setter for publish_date
*/
public function set_publish_date($val) {
// make input date compatible with DB datatype format
return date('Y-m-d',strtotime($val));
}
/**
* magic setter for title
*/
public function set_title($val) {
// auto create slug when setting a blog title
$this->set('slug',\Web::instance()->slug($val));
return $val;
}
public function save()
{
/** @var Base $f3 */
$f3 = \Base::instance();
if(!$this->author)
$this->author = $f3->get('BACKEND_USER')->_id;
return parent::save();
}
} and this is my page controller <?php
namespace Controller;
class Page extends Resource {
public function __construct()
{
$mapper = new \Model\Page();
parent::__construct($mapper);
}
/**
* display a list of page entries
*/
public function getList($f3, $params)
{
$this->response->data['SUBPART'] = 'page_list.html';
$page = \Pagination::findCurrentPage();
if ($this->response instanceof \View\Backend) {
// backend view
$records = $this->resource->paginate($page-1,25,null,
array('order'=>'publish_date desc'));
}
$this->response->data['content'] = $records;
}
/**
* display a single page
*/
public function getSingle($f3, $params)
{
$this->response->data = array('SUBPART' => 'page.html');
$addQuery = '';
// only show published posts, except in backend
if (!$this->response instanceof \View\Backend)
$addQuery = ' and publish_date <= ? and published = ?';
else {
$ui = $f3->get('BACKEND_UI');
if ($f3->get('text_editor') == 'sommernote') {
$f3->set('ASSETS.JS.summernote', $ui.'js/summernote.js');
$f3->set('ASSETS.CSS.fontawesome',
'//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css');
$f3->set('ASSETS.CSS.summernote', $ui.'css/summernote.css');
$f3->set('ASSETS.CSS.summernote-bs3', $ui.'css/summernote-bs3.css');
}
$f3->set('ASSETS.JS.jqueryui', $ui.'js/vendor/jquery.ui.widget.js');
$f3->set('ASSETS.JS.jq-iframe-transport', $ui.'js/jquery.iframe-transport.js');
$f3->set('ASSETS.JS.fileupload', $ui.'js/jquery.fileupload.js');
$f3->set('ASSETS.CSS.fileupload', $ui.'css/jquery.fileupload.css');
}
// select a page by its ID
if (isset($params['id'])) {
$this->resource->load(array('_id = ?'.$addQuery, $params['id'], date('Y-m-d'), true));
$this->response->data['parents'] = array(
array( "id"=>1, "title" => "About Us"),
array( "id"=>2, "title" => "Contact Us"),
);
}
// select a page by its slugged title
elseif (isset($params['slug'])) {
$this->resource->load(array('slug = ?'.$addQuery, $params['slug'], date('Y-m-d'), true));
}
$this->response->data['content'] = $this->resource;
if ($this->resource->dry() && !$this->response instanceof \View\Backend)
$f3->error(404, 'Page not found');
}
/**
* remove a page entry
*/
public function delete($f3, $params)
{
// TODO: erase comments and tag references
parent::delete($f3,$params);
}
public function publish($f3, $params)
{
if ($this->resource->updateProperty(array('_id = ?', $params['id']), 'published', true)) {
\FlashMessage::instance()->addMessage('Your page was published. Hurray!', 'success');
} else {
\FlashMessage::instance()->addMessage('This Page ID was not found', 'danger');
}
$f3->reroute('/admin/page');
}
public function hide($f3, $params)
{
if ($this->resource->updateProperty(array('_id = ?', $params['id']), 'published', false)) {
\FlashMessage::instance()->addMessage('Your page is now hidden.', 'success');
} else {
\FlashMessage::instance()->addMessage('This Page ID was not found', 'danger');
}
$f3->reroute('/admin/page');
}
public function beforeroute()
{
$this->response = \View\Frontend::instance();
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I tried to make page selected it show me error
Object of class Model\Page could not be converted to int
This is code in page_edit.htm
and here is controller code
The text was updated successfully, but these errors were encountered: