Thursday, November 12, 2015

PHP - Render partial view within another controller's view

Goal:
Render a view called view_B within another view called view_A.  Note that view_B belongs to a different controller than view_A and thus is in a different directory.

Solution:
Put this within view_A's code, where "site" is the directory of view_B within the "views" directory and "dashmenu" is the name of view_B.

<?php echo $this->render('//site/dashmenu'); ?>

aka, generically:

<?php echo $this->render('//view_B_Directory/view_B'); ?>

Note that the "//" double slash here denotes the path is within the views directory.


There is also a more verbose way to do this:
<!-- a more verbose way -->
<?php echo Yii::$app->view->render('//site/dashmenu'); ?> 

PHP - Intro

Not a huge fan of PHP but unfortunately I was turned on to a framework called Yii2 to use during my first foray into web development.  My first iteration of a site that is an accompaniment to a piece of internet connected hardware has been built with PHP on the Yii2 framework.  The journey has involved a considerable amount of learning and I have decided to park some of those learnings here on Somewhere in the Boundary Layer.  Thus, you will start seeing tidbits of knowledge that I want to log for future use in short posts.

As an aside, I have been hardware hacking a lot with node.js as well.  Thus, you will find some node and socket.io strewn about the blog as well.  If you're going to follow suite with either choose node.js and not php as node is better suited for event driven programming for connected devices.

Monday, November 2, 2015

Internet Connected LCD

Built an internet connected LCD using an Adafruit Huzzah ESP8266 board, the Arduino IDE, node.js and socket.io.  Here's a short video of it in action and a link to a page where you can write your own message to the LCD screen.  Send your twitter handle to the LCD and I'll tweet a pic of it back at ya!



Here's a page to play with the LCD:

http://fast-bayou-5924.herokuapp.com/


Here's a video of it in action: