CakePHP Elements

Reading time ~1 minute

This is a basic tip which comes in handy. Elements allow you to place blocks of code that are repeated or reused in your application. They also come in handy if you are just looking to tidy up that view of yours.

In this example we are going to take our login form and make it an element. Then we will call it on our page. This tip is to show how to add an element, so don't worry if you don't understand the login code. Lets name this file login.ctp and put it in our /App/View/Elements folder.

<?php echo $this->Form->create('User', array('action' => 'login'));
    echo $this->Form->input('email_address',array('label' => '', 'class'=>'span3', 'placeholder' => 'Email Address'));
    echo $this->Form->input('password',array('label' => '', 'class'=>'span3', 'placeholder' => 'password'));
    echo $this->Form->end(array('label' => 'Sign In', 'value' => 'Sign In', 'class' => 'btn btn-primary'));
    ?>
And in our view file (/App/View/Pages/home.ctp or whatever View you are working on)

<?php echo $this->element('login'); ?>
That's it! You should now have the basics to including an Element in your View! Congratulations! We knew you could do it!>

Quick Laravel/Lumen install with Docker!

The default installer that comes with Laravel is great, but unfortunately that means you have to install dependencies of PHP and Laravel/...… Continue reading

PHP To Python

Published on February 24, 2016

Aftertouch in Logic Pro X and 2015 Macbook Pro

Published on February 24, 2016