Answer the question
In order to leave comments, you need to log in
Advice on how best to form a model for the menu?
There is a table in the database
CREATE TABLE IF NOT EXISTS `pages` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`seo_keywords` varchar(255) NOT NULL,
`seo_description` varchar(255) NOT NULL,
`text` text NOT NULL,
`slug` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
INSERT INTO `pages` (`id`, `title`, `seo_keywords`, `seo_description`, `text`, `slug`) VALUES
(1, 'О магазине', 'ключевые_слова', 'описание', 'текст_страницы', 'about'),
(2, 'Оплата и доставка', 'ключевые_слова', 'описание', 'текст_страницы', 'buy_delivery'),
(3, 'Покупка в кредит', 'ключевые_слова', 'описание', 'текст_страницы', 'buy_credit'),
(4, 'Контакты', 'ключевые_слова', 'описание', 'текст_страницы', 'contacts');
SELECT `title`, `slug`
FROM pages
$pages = Pages::find()
->asArray()
->all();
$sql = 'SELECT `title`, `slug` FROM `pages`';
$pages = Yii::$app->db->createCommand($sql)->queryAll();
$pages = (new Query())
->from('pages')
->all();
Answer the question
In order to leave comments, you need to log in
As convenient and do it, in principle, any option is acceptable.
In terms of MVC and support, it's still better to use a model.
$pages = Pages::find()->asArray()
->all();
$pages = Pages::find()->forMenu()->asArray()
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question