protected static $_has_one = array('i18uk', 'i18ru');
$pages = Model_Page::find('all', array('related' => array('i18uk', 'i18ru')));
foreach ($pages as $p)
{
$pages->arrange = (string) array_search($c->id, \Input::post('arrange'), true);
$p->is_changed('arrange') and $p->save();
}
$p->i18ru = Model_Pages_i18ru::forge();
$p->i18uk = null;
$p->save();
// thrown exception "Call to a member function is_changed() on null"
// fuel/packages/orm/classes/observer/updatedat.php @ line 128
'Orm\\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'relations' => array(
'i18ru', 'i18uk'
),
),
class Model_Page extends \Orm\Model
{
protected static $_properties = array(
'id',
'slug',
'arrange',
);
protected static $_has_one = array(
'i18n' => array(
'key_from' => 'id',
'model_to' => 'Model_Pages_i18n',
'key_to' => 'page_id',
'conditions' => array(), // look at static::_init()
),
'i18ru' => array(
'key_from' => 'id',
'model_to' => 'Model_Pages_i18n',
'key_to' => 'page_id',
'conditions' => array(
'where' => array( array( 'lang', '=', 'ru' ) ),
),
),
'i18uk' => array(
'key_from' => 'id',
'model_to' => 'Model_Pages_i18n',
'key_to' => 'page_id',
'conditions' => array(
'where' => array( array( 'lang', '=', 'uk' ) ),
),
),
);
protected static $_observers = array(
'Orm\\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'relations' => array(
'i18ru', 'i18uk'
),
),
);
public static function _init()
{
static::$_has_one['i18n']['conditions']['where'] = array(
array( 'lang', '=', \Lang::get_lang() )
);
}
public function & __get($property)
{
if (in_array($property, array('title', 'menu', 'body', 'meta_title', 'meta_keywords', 'meta_description')))
{
$result = ($this->i18n) ? $this->i18n->$property : \Lang::get_lang().' '.$property;
$result =& $result;
return $result;
}
else
{
return $this->get($property);
}
}
}
function action_index()
{
$pages = Model_Page::find('all', array('related' => array('i18n', 'i18ru', 'i18uk')));
if ($arrange = \Input::post('arrange'))
{
foreach ($pages as $p)
{
unset($p->i18n, $p->i18ru, $p->i18uk);
$p->arrange = (string) array_search($p->id, $arrange, true);
$p->is_changed('arrange') and $p->save();
}
\Response::redirect_back();
}
$this->template->title = __('global.text_pages');
$this->template->content = \View::forge('admin/page/index')->set('pages', $pages);
}
It looks like you're new here. If you want to get involved, click one of these buttons!