How to set data from database to element?

Hello guys i am new in cakephp and php too. I have changed default layout to me template and created 1 controller with index method, but also i created 2 lements menu( in top ) and footer in bottom how can get data from my database to my elements?

layout

<?php
$cakeDescription = __d('venere', 'Venere: Оливки масла маслины');
?>


 <!DOCTYPE html>
<html lang="ru">
    <head>
        <?php echo $this->Html->charset(); ?>
        <!-- Responsive meta -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- IE Compatibility meta -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
       	<?php
       	echo $this->Html->meta('icon');

		echo $this->Html->css(['bootstrap.min','https://file.myfontastic.com/6AeAYiqp5KBjSiZ2tE8WJW/icons.css','https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css','slider.min','lightbox.min','datepicker.min','timepicki.min','owl.carousel.min','style.default']);
		echo $this->Html->script(['https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js','bootstrap.min','jquery.ba-cond.min','jquery.slitslider.min','owl.carousel.min','lightbox.min','datepicker.min','datepicker.en.min','timepicki.min','jquery.validate.min','smooth.scroll.min','script']);

		echo $this->fetch('meta');
		echo $this->fetch('css');
		echo $this->fetch('script');
		?>
        <!-- Page Title -->
        <title>
		<?php echo $cakeDescription ?>:
		<?php echo $this->fetch('title'); ?>
		</title>

        <!-- Modernizr -->
        <script type="text/javascript" src="js/modernizr.custom.79639.min.js"></script>
    </head>
    <body>

        <div class="page-holder">
            <!-- Navbar -->
            <header class="header">
               <?=$this->element('menu')?>
            </header><!-- End Navbar -->

  
<?php echo $this->fetch('content'); ?>

   
            <!-- Footer -->
           <?=$this->element('footer')?>
            <!-- End Footer -->

            <!-- scroll top btn -->
            <div id="scrollTop" class="btn-unique">
                <i class="fa fa-angle-up"></i>
            </div><!-- end scroll top btn -->

        </div>
       
    </body>
</html>

element footer





italiano

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.


                        <div class="col-md-4 contact">
                            <div class="header">
                                <h6>Contact</h6>
                            </div>
                            <ul class="contact list-unstyled">
                                <li><span class="icon-map text-primary"></span>Basioun, 23 July st, Egypt</li>
                                <li><a href="mailto:Italiano@Company.com"><span class="icon-phone text-primary"></span>Italiano@Company.com</a></li>
                                <li><span class="icon-mail text-primary"></span>9465 7675 294</li>
                                <li><span class="icon-printer text-primary"></span>333-999-666</li>
                            </ul>
                        </div>

                        <div class="col-md-4 newsletter">
                            <div class="header">
                                <h6>Newsletter</h6>
                            </div>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmo.</p>
                            <form action="#" id="subscribe" class="clearfix">
                                <input type="email" name="subscribtion-email" placeholder="Enter Your Email Address" class="pull-left">
                                <button type="submit" class="btn-unique has-border pull-left">Subscribe</button>
                            </form>
                        </div>
                    </div>

              
                </div>

                <div class="copyrights">
                    <div class="container">
                        <div class="row">
                            <div class="col-sm-5">
                                <ul class="list-unstyled list-inline">
                                    <li><a href="#">Policy Privacy</a></li>
                                    <li><a href="#">Terms of Use</a></li>
                                    <li><a href="#">Contact</a></li>
                                </ul>
                            </div>

                            <div class="col-sm-7">
                                <p>&copy; 2017 Italiano Restaurant. Template By <a href="https://bootstraptemple.com/" target="_blank">BootstrapTemple.com</a></p>
                                <!-- Please do not remove the backlink to us unless you have purchased the attribution-free license at https://bootstraptemple.com. It is part of the license conditions. Thanks for understanding :) -->
                            </div>
                        </div>
                    </div>
                </div>
            </footer>

What you exactly want to achieve? Isn’t your menu and footer permanent? Are they changing based on something? Why do you need to query the database for these?

If you are new to the PHP then You shouldn’t use framework, for now, learn Php to an intermediate level then go for the framework. And for your question, go through edit() function of your controller and edit.ctp view. You can easily figure it out that how a data from a database is been fetched. I would also recommend you to use book.cakephp it has all the solution. Try it and if you still failed to do so, show us what you have tried, then I will help you. But you must try it yourself first.

1 Like