PHP code example of slaxweb / ci-basecontroller

1. Go to this page and download the library: Download slaxweb/ci-basecontroller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

slaxweb / ci-basecontroller example snippets



class Contrlr extends \SlaxWeb\BaseController\BaseController
{
  public function showView()
  {
    // nothing, that's enough
    // base controller will load application/views/contrlr/showview/main.php view file
    // if the controller is located in a sub-dir, sub-dir is also  }
  
  public function viewWithData()
  {
    $this->viewData = array("name" => "value");
  }
}

$this->view = false

$this->view = "desired/view";

$this->subViews = array(
    "name"  =>  array(
        array(
            "view"  =>  "subview/file",
            "data"  =>  array(
                "subviewParameter"  =>  "value"
            )
        )
    )
);

 echo $subview_name; 

$this->viewData = array("name" => "value");


class Contrlr extend \SlaxWeb\BaseController\BaseController
{
  public function injectLanguage()
  {
    // you're done, default view is loaded with default language and its prefixed language strings.
  }
  
  public function noLang()
  {
    $this->langFile = false;
  }
  
  public function diffLangFile()
  {
    $this->langFile = "Diffrent";
  }
  
  public function diffPrefix()
  {
    $this->langPrefix = "custom_prefix_";
  }
  
  public function nonDefaultLanguage()
  {
    $this->language = "german";
  }
}

class Contrlr \SlaxWeb\BaseController\BaseController
{
  public function defaultLang()
  {
  }
}

$lang["defaultLang_var1"] = "string";
$lang["defaultLang_var2"] = "string";
$lang["defaultLang_var3"] = "string";

$this->langFile = false;

$this->langFile = "Different";

$this->langFile = array("Lang1", "Lang2", "Lang3");

$this->langPrefix = "langprefix_";

$this->language = "german";

class Contrlr extends \SlaxWeb\BaseController\BaseController
{
  // DEPRECATED
  public function template()
  {
    $this->head = "head/view";
    $this->foot = "foot/view";
  }
  
  // DEPRECATED
  public function noTemplate()
  {
    // if a template is already loaded, you can disable it
    $this->ant your method or whole controller to have a specific
layout file you can set it to the layout property
    $this->layout = "layout/view";
  }
}

$this->head = "head/view";
$this->foot = "foot/view";

$this->

// use controller or application specific layout
$this->layout = true;
// use custom layout
$this->layout = 'layout/myLayout';

class Cntrlr extends \SlaxWeb\BaseController\BaseController
{
    // Autoload models Model1_model and Model2_model
    public $models = array("Model1", "Model2");

    public function someMethod()
    {
        // now just use the model:
        $this->Model1->modelMethod();
        $this->Model2->modelMethod();
    }
}