Giter VIP home page Giter VIP logo

Comments (3)

ikkez avatar ikkez commented on August 29, 2024

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.

RNKushwaha avatar RNKushwaha commented on August 29, 2024

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.

RNKushwaha avatar RNKushwaha commented on August 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.