Comments (3)
Well it looks to me, that your @content.parent_id
contains a Page model object, and not an integer.
I have no idea what your page model looks like or what you are doing with your data in your controller or db with your custom model. so i can't really help you that much. sorry.
from fabulog.
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();
}
}
from fabulog.
However I solved the problem (as you suggested) using
<F3:repeat group="{{ @Parents }}" value="{{ @item }}">
<option value="{{@item.id}}" {{(@item.id == @content.parent_id.id)?'selected':''}}>{{@item.title}}
/F3:repeat
Thanks
from fabulog.
Related Issues (20)
- Admin user can be deleted HOT 1
- Should check csrf in forms? HOT 5
- Feature request - Multilanguage module (f3-multilang) HOT 2
- Rewrite rule is redirecting www.mysite.com to mysite.com HOT 4
- Dynamic meta info in header section HOT 2
- Logical Error in User Model
- related content HOT 3
- does not work with MySQL HOT 1
- Trying to redirect to another controller... HOT 2
- In php7.2 bug HOT 1
- Demo is throwing error HOT 1
- about comment
- upload an image from admin/post have some error. HOT 1
- trying the demo version with admin user at https://ikkez.de/fabulog/admin/post Gives Internal server Error HOT 2
- Update?
- postgres HOT 2
- How to run custom query like db->exec() in a controller? HOT 3
- db using HOT 2
- Fatal error when page does not exits HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fabulog.