View Single Post
  #2  
Old 09-23-2014, 06:18 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,598
IntoRain is on a distinguished road
Default

In 1.3.4, pages are divided into Controller and View. That means for each new page you need a Controller and a View file. The View is what you show to the user and the Controller is basically treating the information and passing it to the View

For example, your yoursite.com/adopt page is built using the files: adopt.php (controller) and adoptview.php (viewer). All view pages are inside view folders (there are two: one in your mysidia folder, related to player pages, and one inside admincp folder for ACP pages).


To create an yoursite.com/explore page, you need to:

1) Create an explore.php file (same directory as adopt.php, account.php, etc.) with at least these contents:

PHP Code:
<?php

use Resource\Native\String;

//note the name ExploreController. If you wanted a page called mypage it would be MyPageController and the file would be mypage.php
class ExploreController extends AppController{

    
    public function 
__construct(){
        
parent::__construct("member");
    
$mysidia Registry::get("mysidia");
        
    
//use the following three lines to make it admin-only
    
if($mysidia->usergroup->getpermission("canmanageadopts") != "yes"){
        throw new 
NoPermissionException("You do not have permission to access this page.");
    }    
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
        
//this is how you pass stuff to the view file
        
$this->setField("hello",new String("Hello world!"));    

    }
    
}
?>

2) Create an exploreview.php file (inside the view folder with adoptview.php, accountview.php, etc.):

PHP Code:
<?php

//note the name ExploreView. If you wanted a page called mypage it would be MyPageView and the file would be mypageview.php
class ExploreView extends View{
    
    public function 
index(){
    
        
//the view file messes with the document (page content)
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
            
$document->setTitle("Title Test");//needs a title to work
            
        //this is how you get stuff from the controller
            
$hello $this->getField("hello");
  
          
//add the contents of the variable hello to the document
            
$document->add(new Comment($hello));
    }

    
}
?>
To make a page like yoursite.com/explore/add, you need to add the method add() similar to index(), for both the ExploreController and the ExploreView
This is also the same concept for ACP pages.
__________________


asp.net stole my soul.

Last edited by IntoRain; 09-23-2014 at 06:22 PM.
Reply With Quote