![Old](entertainage/statusicon/post_old.gif)
01-19-2015, 12:35 PM
|
![Kyttias's Avatar](image.php?u=15002&dateline=1452391049) |
Premium Member
|
|
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 99,811
|
|
Index Page Mod (Use PHP inside Index!)
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 Code:
<?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).
PHP Code:
$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.
PHP Code:
/* 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!
PHP Code:
$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");).
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Last edited by Kyttias; 03-05-2016 at 10:14 AM.
|