We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Assign data from view to layout

Hi, I want to send data from view to layoout, how can I do this ?

thanks.



85.5k
Accepted
answer

that makes no sence ?

but your view data is available in your layouts as well as in your views

edited Nov '18

Instead of MVC architecture, you might want to revert back to Spaghetti one.

https://docs.phalcon.io/en/3.4/views

Views represent the user interface of your application. Views are often HTML files with embedded PHP code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.

edited Nov '18

I've maked a breadcrumbs widget and I needed to send breadcrumbs data to layout.

I call one time the widget in layout, and every where I need to render this widget just set $breadcrumbs variable in my view.

My View:

$title = 'User List';

$breadcrumbs[] = ['label' => 'Users', 'url' => $this->url->get('user/index')];

$breadcrumbs[] = $title;

My Layout:

<?= \Multiple\Widget\Breadcrumb::widget([ 'items' => $breadcrumbs ?? [], ]) ?>



85.5k

you can "borrow" some ideas from here

https://github.com/phalcon/breadcrumbs

Thanks.

Is wrong my way ? I got this idea from Yii2 framework.

you can "borrow" some ideas from here

https://github.com/phalcon/breadcrumbs



85.5k

its fine I just gave it to you just in case you need someting else