PDA

View Full Version : Mys 1.3.4 Index Page Mod (Use PHP inside Index!)


Kyttias
01-19-2015, 12:35 PM
new indexI really wanted to use some PHP inside my index page, but because it was hooked up to the AdminCP as a custom document, no matter how many modifications I made to CKEditor, I still couldn't get it to work. So... I turned to HoF and asked about it. It turns out, we can just modify our view/indexview.php to be like all the other files in view/, and modify it similarly:

<?php

class IndexView extends View{

public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle(" Your Title Here ");

$document->add(new Comment("<!-- START -->

<p> Place all your html here! </p>

<div class='well'>
<p>You MUST use single quotes around src/class/id/attributes/inline styles!!</p>
<span style='float: left;'>Don't forget!</span>
</div>

<!-- END -->", FALSE));

}
}
?>


If you ever must use quotations in your html, be sure to cancel them out by adding a backslash before them. \"Okay?\", she asks.

If you ever feel the need to break your html to write more PHP, be sure to close it. Our html is inserted into Comments, so be sure to properly close it. The FALSE parameter means there will be no linebreak. If you leave FALSE out, there will be a linebreak (that is, a <br> will be inserted).
$document->add(new Comment(" Our HTML here! ", FALSE));


working with variablesNow you're free to add php wherever you need to. To print a variable into your html, wrap it inside inside {brackets} and always start with a $. Be sure to set variables before you need to use them, to get the intended results.


/* This will set $name to "Guest" if logged out, or the user's username if logged in! */
$name = (!$mysidia->user->isloggedin)?"Guest":$mysidia->user->username;

$document->add(new Comment(" Welcome, {$name}! ", FALSE));



five random petsFor something more complicated, try adding this inside the index function! It will show you five random pets!

$document->add(new Comment("<div class='row'><h4>Random 5 Pets</h4>", FALSE));
$stat_rand5 = $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY RAND() DESC LIMIT 5");
while($aid = $stat_rand5->fetchColumn()){
$adopt = new OwnedAdoptable($aid);
$document->add(new Comment("
<div style='display: inline-table; text-align: center;'>
<a href='levelup/click/{$adopt->getAdoptID()}'><img src='{$adopt->getImage()}'></a></br>
<a href='levelup/click/{$adopt->getAdoptID()}'><b>{$adopt->getName()}</b></a> the <small><b>LVL.</b> {$adopt->getCurrentLevel()}</small> {$adopt->getType()}</div>
", FALSE));
}
$document->add(new Comment("</div>", FALSE));

You might need to set a width on those images with some inline styling (perhaps even one that's a percentage, which is entirely why I'm not using $this->adopt->getImage("gui");).

MikiHeart
01-19-2015, 10:49 PM
Thank you <3 I was going to do this myself.
I didn't think of listing pets though!
I will be adding news from the news addon onto my front page. That will be fun! I'll share that code when I've got it ^^