Welcome Guest, Not a member yet? Register   Sign In
Help meeee - is this feasible for codeigniter implementation
#1

[eluser]Subclass[/eluser]
Hi All - First Post,

I've been going mental with my PHP development, and seriously feel like I need a better solution as I'm coding it new from scratch almost every time and it's draining my time and efforts.
Was wondering if this kind of approach is feasible for code igniter - only slight issue is that I currently rewrite all requests through index.php allowing me to have any url for pages

I'm basically splitting my application into 4x parts

1. Objects - basically properties and a constructor (no clever stuff)
2. Wiring - classes to construct objects (run db query, get data, create 'new' objects & return)
3. Templates - no php code here, just placeholders
4. Index - .htaccess rewrites all requests (except images/robots.txt/admin/etc)

Problems I have (why I haven't put it into CI earlier) - have the requirement for custom urls - not /1/2/3 architecture

Lack of understanding


Objects
--------

page.php

Code:
class Page
{
public $id;      // autogen from mysql
public $name; public $url; public $seotitle; public $seodescription
....

public function __construct
(
$id,$name,$url,$seotitle,$seodescription,....
)
{
$this->id = $id; $this->name = $name; ....
}
}

Wiring
-------

pages.php

Code:
class Pages
{
static function get_page($id)
{
$query = "SELECT * FROM `pages` WHERE `id` = {$id}";
$res = mysql_query($query);
$row = mysql_fetch_object($res);

switch($row->type)
{
  case "homepage":
  return new homepage($row->id, $row->name, $row->url ....);
  break;
  case "page":
  return new page($row->id, $row->name, $row->url ...);
}
}
static function get_all_type_pages($type)
{
  // select * from pages where `type`= $type
  // return array of page objects
}
}


Templates
-----------
basically html files with placeholders %field1%, %field2%, <title>%seotitle</title> etc


Main File (index.php)
----------------------------
Code:
require(settings.php); // domain, mysql, constants etc
require(pages.php);

// get page id
$request = $_SERVER['REQUEST_URI'];
$query = "SELECT * FROM `pages` WHERE BINARY `url` = '{$request}'";
$res = mysql_query($query);
if(mysql_num_rows($res) < 1)
{
//throw 404/intelligent sitemap
exit();
}
$page = Pages::get_page($id);

switch(instanceOf $page)
{
    case "homepage":
        $page['content1'] = $page->content1;
        $page['content2'] = $page->content2;
        $output = file_get_contents("templates/homepage");
        break;
}

foreach(array_keys($page) as $key)
{
   $output = preg_replace("/%$key%/",$page[$key],$output);
}
echo $output;

Any feedback much appreciated ???


Messages In This Thread
Help meeee - is this feasible for codeigniter implementation - by El Forum - 06-29-2009, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB