Project code structure See what I wrote earlier [Ext/fckeditor integration--AJAX UI--a new way of thinking about web development, changing ideas in time].
In the
├─taskofpig
│├─controller
│├─dao
│├─js
│├─music
│├─tpl
│├─tpl_c
│└─_log
The project code is as follows:
Db.sql
SET foreign_key_checks=0;
-- ----------------------------
--Table structure for task
-- ----------------------------
CREATE TABLE ' Task ' (
' id ' int (one) not NULL,
' title ' varchar (m) Collate utf8_unicode_ci not NULL,
' desc ' text collate utf8_unicode_ci,
' Date ' datetime not NULL,
' Created ' int (one) default NULL,
' Updated ' int (one) default NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 collate=utf8_unicode_ci;
-- ----------------------------
--Table structure for TASK_SEQ
-- ----------------------------
CREATE TABLE ' Task_seq ' (
' id ' int (one) not NULL
) Engine=myisam DEFAULT Charset=utf8 collate=utf8_unicode_ci;
/ucren/taskofpig/index.php
<?php
Set the correct time zone
Date_default_timezone_set ("Asia/shanghai");
Define (' Taskofpig_dir ', DirName (__file__));
Require ('.. /phplibs/flea/flea.php ');
Configure $globals[g_flea_var][' Class_path '
Flea::import (Taskofpig_dir); Add the current directory to the environment variable
Flea::loadappinf (' appconfig.php '); Separate configuration files for easy maintenance
Flea::init ();
Since Flea_db_tabledatagateway is not automatically loaded, it is necessary to explicitly load
Flea::loadclass (' Flea_db_tabledatagateway ');
Flea::runmvc ();
?>
/ucren/taskofpig/appconfig.php
<?php
Configuring the $GLOBALS [g_flea_var][' App_inf ']
Return Array (
' Dispatcher ' => ' flea_dispatcher_simple ',//Custom Scheduler Flea_dispatcher_auth
' Controlleraccessor ' => ' ctl ',
' Actionaccessor ' => ' act ',
' View ' => ' flea_view_smarty ',//Custom views
' Viewconfig ' => Array (
' Smartydir ' => '. /phplibs/smarty ',
' Template_dir ' => './tpl ',
' Compile_dir ' => './tpl_c ',
' Left_delimiter ' => ' <% ',
' Right_delimiter ' => '%> ',
' Debugging ' => false
),
' DbDSN ' => Array (//Custom database connection parameters
' Driver ' => ' MySQL ',
' Host ' => ' localhost ',
' Login ' => ' dbuser ',
' Password ' => ' Dbpass ',
' Database ' => ' dbname ',
' CharSet ' => ' UTF8 '
) ,
' Logfiledir ' => './log ',//custom log
' LogFileName ' => ' Task_admin.log '
);
?>
/ucren/taskofpig/dao/table.php
<?php
The task schedule of the Angry Pig
Class Dao_tasktable extends Flea_db_tabledatagateway
{
Specify data table name
var $tableName = ' Task ';
Specify primary key field name
var $primaryKey = ' id ';
}
?>
/ucren/taskofpig/controller/default.php
<?php
Flea::loadfile (' dao_table.php ', true);
Flea::loadfile (' flea_ajax_json.php ', true);
Class Controller_default extends Flea_controller_action
{
var $smarty;
function Controller_default ()
{
$this->smarty = $this->_getview ();
$this->smarty->assign (' sitename ', ' task schedule--Angry pig ');
$this->smarty->assign (' opname ', ' Task List ');//default should change the value in the child module
}
function Actionindex ()
{
$this->tomodulepage (); Default Display Task List page
}
Defines a function to invoke FCKeditor
function Call_fck ($input _name, $input _value, $w = ' a ', $h = ' 400 ')
{
Include_once '.. /fckeditor/fckeditor.php ';
$fcked = new FCKeditor ($input _name);
$fcked->basepath = '.. /fckeditor/';
$fcked->toolbarset = ' Default '; Toolbar settings
$fcked->instancename = $input _name;
$fcked->width = $w;
$fcked->height = $h;
$fcked->value = $input _value;
$FCK _area = $fcked->createhtml ();
$this->smarty->assign (' Fck_area ', $fck _area);
unset ($fck _area);
Unset ($fcked);
}
function _showpage ($tpl = ' taskofpig.main.html ')
{
$this->smarty->display ($TPL);
}
function Actionadd ()
{
$this->addtask ();
}
function Actionupdate ()
{
$this->updatetask ();
}
function Deletetask ($id) {
$row = array (' ID ' => $id);
$thisDao = & New Dao_tasktable ();
$status = $thisDao->remove ($row); Returns a Boolean value
Unset ($thisDao);
return $status;
}
function Listtask ()
{
$thisDao = & New Dao_tasktable ();
$rows = $thisDao->findall (); Two-dimensional array
foreach ($rows as & $row)//note here to pass the reference
{
$row [' desc '] = mb_substr ($row [' desc '],0,40, ' UTF-8 ');
}
$this->smarty->assign (' RowSet ', $rows);
$this->_showpage ();
}
function AddTask ()
{
$thisDao = & New Dao_tasktable ();
$row = Array (
' title ' => $_request[' title '],
' desc ' => $_request[' desc '],
' Date ' => $_request[' date ']
);
$commitId = $thisDao->create ($row);
Unset ($thisDao);
echo "Successfully add new task";
Redirect (URL ("Default"), 1);
}
function Updatetask ()
{
$thisDao = & New Dao_tasktable ();
$row = Array (
' id ' => $_request[' id '],
' title ' => $_request[' title '],
' desc ' => $_request[' desc '],
' Date ' => $_request[' date ']
);
$commitId = $thisDao->update ($row);
Unset ($thisDao);
echo "Successful update task";
Redirect (URL ("Default"), 1);
}
function Querytask ($id) {
$thisDao = & New Dao_tasktable ();
$row = $thisDao->find (array (' ID ' => $id));
Unset ($thisDao);
return $row;
}
function querytaskfordate ($date =null)
{
$thisDao = & New Dao_tasktable (); ' 2008-08-17 07:42:29 '
$row = $thisDao->find Array (' Date ' =>date (' y-m-d h:i:s '));
Unset ($thisDao);
if (!empty ($row))
{
$jsonobj = new Services_json ();
echo $jsonobj->encode ($row);
}
Else
Die (Date (' y-m-d h:i:s '));
}
Task Flow control method
function Tomodulepage ()
{
if ($_request[' op '] = = ' Search ') {
$this->querytaskfordate ();
}
else if ($_request[' op '] = = ' Add ') {
$this->smarty->assign (' opname ', ' Add New Task ');
$this->smarty->assign (' Tasktime ', date (' y-m-d h:i:s '));
$this->call_fck (' desc ', ');
$this->_showpage (' taskofpig.add.html ');
}
else if ($_request[' op '] = = ' del ') {
if (Isset ($_request[' id ')) && is_numeric ($_request[' id '))
$status = $this->deletetask ($_request[' id '));
$this->listtask ();
}
else if ($_request[' op '] = = ' edit ') {
if (Isset ($_request[' id ')) && is_numeric ($_request[' id ')) {
$row = $this->querytask ($_request[' id '));
}
$this->call_fck (' desc ', $row [' desc ']);
unset ($row [' desc ']);
$this->smarty->assign (' RowSet ', $row);
$this->smarty->assign (' opname ', ' Modify task ');
$this->_showpage (' taskofpig.edit.html ');
}
else {//list
$this->listtask ();
}
}
}
?>
Current 1/2 page
12 Next read the full text