Welcome Guest, Not a member yet? Register   Sign In
class Page and Db
#1

[eluser]cPage[/eluser]
They told me to keep it simple.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Yaml extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->library('Page',array('title'=>'Yaml'));
  $this->load->library('Db');
  $this->page->set_lang('en');
  $this->page->add_meta(array('name'=>'viewport','content'=>'width=device-width,initial-scale=1.0'));
  $this->page->add_meta(array('name'=>'description','content'=>'Yaml CSS framework'));
  $this->page->add_css('base','assets/css/yaml/core');
  $this->page->add_css('iehacks','assets/css/yaml/core');
  $this->page->add_css('hlist','assets/css/yaml/navigation');
  $this->page->add_css('central','assets/css/yaml');
  $this->page->add_css('gray-theme','assets/css/yaml/forms');
  $this->page->add_css('screen','assets/css/yaml/screen');
  $this->page->add_css('typography','assets/css/yaml/screen');
  $this->page->add_css('print','assets/css/yaml/print');
  $this->page->add_css('screen-FULLPAGE-layout','assets/yaml/screen');
}

public function index()
{
  //-- HEADER
  $this->page->set_html('h1','htitle','YAML : css framework');
  $this->page->set_view('header',$this->page->get_html());
  //-- 3 COLUMNS (Default)
  $this->page->set_html('p','just-an-id',$this->db->data['texts'][11]['text']);
  $this->page->set_html('div',NULL,$this->page->get_html(),'ym-cbox');
  $this->page->set_html('div','dcol1',$this->page->get_html(),'ym-col1');
  $this->page->set_child();
  
  $this->page->set_html('p',NULL,$this->db->data['texts'][11]['text']);
  $this->page->set_html('div',NULL,$this->page->get_html(),'ym-cbox');
  $this->page->set_html('div','dcol2',$this->page->get_html(),'ym-col2');
  $this->page->set_child();
  
  $this->page->set_html('h4',NULL,'Column 3 : screen-FULLPAGE-layout');
  $this->page->set_html('p',NULL,$this->db->data['texts'][11]['text']);
  $this->page->set_html('div',NULL,$this->page->create_html(NULL,CONCAT),'ym-cbox');
  $this->page->set_html('div','dcol3',$this->page->get_html(),'ym-col3');
  $this->page->set_child();  
  
  $this->page->set_parent();
  // -- CONTENT
  $this->page->set_html('div','main',$this->page->create_html(),'ym-column');
  $this->page->set_view('content',$this->page->get_html());
  
  // -- FOOTER
  $this->page->set_html('h4',NULL,'screen-FULLPAGE-layout');
  $this->page->set_view('footer',$this->page->get_html());
  $this->compile();
}
  
public function compile()
{
  $fname = $this->page->to_ascii($this->page->title);
  if( file_exists('./html/'.$fname.'.html'))
  {
   $t['all'] = file_get_contents('./html/'.$fname.'.html');
  }
  else
  {
   $t['all'] = $this->page->create_page('yaml/layout',SAVE);
  }
  $this->load->view('all',$t);
}
}
#2

[eluser]cPage[/eluser]
A exemple of one of my views. This view called ini.php to initialize all assets needed and configurations of the HTML header.
Code:
<?php
$this->page->add_meta(array('charset'=>'utf-8'));
$this->page->add_meta(array('name'=>'description','content'=>$this->page->description));
$this->page->add_meta(array('name'=>'author','content'=>'cPage'));
$this->page->set_assets_path('assets');
$this->page->add_link(array('rel'=>'shortcut icon','href'=>ASSETS.'images/favicon.ico'));
$this->page->add_link(array('rel'=>'apple-touch-icon','href'=>ASSETS.'images/apple-touch-icon.pn'));
$this->page->add_css('tinyfluid','screen');
$this->page->add_css('button','screen');
$this->page->add_js_head(ASSETS.'js/modernizr-2.5.3.min.js');
$this->page->add_js_head(ASSETS.'js/preload.js');
$this->page->add_js_body(ASSETS.'js/general.js');
$this->page->add_js_body(ASSETS.'js/jquery-1.7.1.min.js');
$this->page->set_google('analytic','UA-XXXXX-X');

I will continue to improve this library.(Page.php) and write in here the evolution. Is that all right to do that ?
#3

[eluser]cPage[/eluser]
A good thing about this library, its that it give you all the flexibility that you want. For exemple you can set a view as a bloc of code and use it anywhere in the controller with the function get_view();

Code:
$this->page->set_html('h3','Lorem Ipsum');
$this->page->set_html('p','Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.');
$this->page->set_html('div',$this->page->create_html(),array('class'=>'box'));
$this->page->set_html('aside',$this->page->get_html(),array('class'=>'grid_3'));
$this->page->set_view('aside',$this->page->get_html());

The function set_html takes 3 parameters. 2 are optional. set_html($tag [,mixed $value][,array $attributes])

create_html() compile into 1 string all the previous sets.
get_html() return the last compress string of html that comes from create_html or set_html.






Theme © iAndrew 2016 - Forum software by © MyBB