Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

adding new pages


Go to End
Reply


2 Posts   1229 Views

Avatar
Solo

Community Member, 32 Posts

9 March 2010 at 3:14pm

Edited: 09/03/2010 3:15pm

Sorry for stupid questions, but i m stuck: I make two pages types, the Hotel.php:

<?php
class Hotel extends Page {
	static $db = array(
		'Title' => 'Varchar(50)',
		'Description' => 'Text',
		'Location' => 'Text',
		'Zvezd' => 'Text',
		'Adress' => 'Varchar(100)',
		'Telefone' => 'Varchar(100)',
		'Price' => 'Text',
    );   
	static $has_one = array(
	'Image' => 'Hotel_Image',
	'HotelHolder' => 'HotelHolder',
    );
	static $default_parent = 'HotelHolder';
	static $can_be_root = false;
	
	static $singular_name = 'Гостиница';
	static $plural_name = 'Гостинницы';
	
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Main', new TextAreaField('Description', 'Описание'));
		$fields->addFieldToTab('Root.Content.Main', new TextField('Location', 'Местоположение'));
		$fields->addFieldToTab('Root.Content.Main', new TextField('Zvezd', 'Кол-во звезд'));
		$fields->addFieldToTab('Root.Content.Main', new TextField('Adress', 'Адрес'));
		$fields->addFieldToTab('Root.Content.Main', new TextField('Telefone', 'Телефон'));
		$fields->addFieldToTab('Root.Content.Main', new NumericField('Price', 'Цены'));
		return $fields;
	}
	
}
	
class Hotel_Controller extends Page_Controller {
 
}

?>

and the hotelHolder.php:

<?php

class HotelHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    static $has_many = array(
	'Hotels' => 'Hotel'
    );
    static $allowed_children = array('Hotel');

}
 
class HotelHolder_Controller extends Page_Controller {

	function addHotelForm(){                               
    return new Form($this, "addHotelForm",
        new FieldSet(
			new TextField('Title', 'Название'),
            new TextareaField('Description', 'Описание'),
            new TextField('Location', 'Местоположение'),  
            new TextField('Zvezd', 'Кол-во звезд'),
			new TextField('Adress', 'Адрес'),
			new TextField('Telefone', 'Телефон'),
			new NumericField('Price', 'Цены'),
			new ImageField('Hotel_Image', 'Фото Гостиннцы')
        ),
       new FieldSet(
            new FormAction("doSubmitHotel", "добавить новую гостинницу")
       ), 
			new RequiredFields(
            'Description'
       )
    );
	}

//Функция обработки формы добавления новой гостинницы
	function doSubmitHotel($data, $form){
		$hotel = new Hotel();
		$form->saveInto($hotel);
		$hotel->HotelCategoryID = $this->dataRecord->ID;
		$hotel->write();
		$form->sessionMessage(
			'Гостинница успешно добавлена!',
			'good'
		);
		Director::redirectBack();
		return;
	}
 
}

?>

adding new hotel pages is ok in the cms(backend), but, when i tried to add page through frontend - the new pages puts in the root folder not in hotelHolder as i want. What is wrong with my code? Can somebody help?

Avatar
Solo

Community Member, 32 Posts

12 March 2010 at 7:50pm

I found the answer: $hotel->HotelCategoryID = $this->dataRecord->ID; must be $hotel->HotelHolderID = $this->dataRecord->ID