Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting numbers of Item content #1227

Closed
apnmyid opened this issue Mar 8, 2017 · 1 comment
Closed

Getting numbers of Item content #1227

apnmyid opened this issue Mar 8, 2017 · 1 comment
Assignees
Milestone

Comments

@apnmyid
Copy link

apnmyid commented Mar 8, 2017

What steps will reproduce the problem?

controller:

namespace app\modules\news\frontend\controllers;
class DefaultController extends \luya\web\Controller
{
    public function actionIndex()
    {
        $model = Yii::$app->menu->findAll(['depth' => 1, 'container' => 'news']);
        return $this->render('index', [
            'model' => $model
        ]);
    }
}

view: index.php

<?php foreach ($model as $item): ?>
    <h3><?= $item->title ?></h3>
    <p>
        <?= \luya\helpers\StringHelper::truncate($item->getModel()->activeLanguageItem->getContent(), 200, "<a href=\"$item\">Read more...</a>", null, true) ?>
    </p>
<?php endforeach; ?>

What is the expected result?

I know this is expected behavior. But maybe it will produce minimal query if the Item object has getContent() method that returning content from $itemArray['content']

What do you get instead? (A Screenshot can help us a lot!)

Multiple query

image

LUYA Check ouput (run this script and post the result: luyacheck.php)

Additional infos

Q A
LUYA Version dev-master
PHP Version 5.6.30
Platform Apache/2.4.23 (Win32) OpenSSL/1.0.2h mod_fcgid/2.3.9 Server
Operating system Windows 10 x64
@nadar nadar self-assigned this Mar 11, 2017
@nadar nadar added this to the 1.x milestone Apr 10, 2017
@nadar nadar modified the milestones: 1.0.0, 1.x Apr 13, 2017
@nadar
Copy link
Contributor

nadar commented Apr 13, 2017

@alponso I just added an ability to preload all models for a given menu query, this should reduce your sql requests. You can use it like this:

change
$model = Yii::$app->menu->findAll(['depth' => 1, 'container' => 'news']);
to
$model = Yii::$app->menu->findAll(['depth' => 1, 'container' => 'news'], true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants