/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function SmartPageRoutes($action, $slug=NULL, $filename=NULL, $page=NULL) { if($slug!=NULL) $slug = $this->_generateSlug($slug); // Add link to routes file $routeFile = '../primary_app/config/routes.php'; foreach ($arr as $key => $line) { if($action == 'add') { // Match all the public functions $arr[$key] = $line."n".'$route[''.$slug.''] = "'.$filename.'";'."n"; $arr[$key] = $line."n".'$route[''.$slug.'/(.*)'] = "'.$filename.'/$1";'."n"; } else if($action == 'update') { // Match the previous route $urlPage = '$route[''.$page->linkSlug.'(.*)']'; $urlClass = '$route[''.$page->linkSlug.'/(.*)(.*)']'; { $arr[$key] = "n".'$route[''.$slug.$child[1].''] = "'.$filename.'";'."n"; } { $arr[$key] = "n".'$route[''.$slug.$child[1].''] = "'.$filename.'/$1";'."n"; $updateMatch = 1; } } else if($action == 'delete') { // Match the previous route $urlPage = '= "smart_pages/'.$page->pageSmartPageFileName; { $arr[$key] = ""; } } } // Let's make sure the file exists and is writable first. { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. { echo "Cannot open file ($routeFile)"; exit; } // Write $somecontent to our opened file. { echo "Cannot write to file ($routeFile)"; exit; } return true; } else return false; }