i'm using codeigniter , have project lot of pages. each page consist of controller + view. maybe there way automatically create pages , controllers base on template? maybe codeigniter has batch file option detects changes in specific table (pages table example) in database , create controller + view files accordingly?
thanks
found way create 'batch' file create model/view/controller
enjoy.
i used codeigniter's helper so.
from controller load helper
$this->load->helper('pages_creator'); create_new_page('test', 'test', 'test');
here helper pages_creator_helper.php
<?php function create_new_page($page_name, $class_name, $controller_name){ // create controller $controller = fopen(apppath.'controllers/'.$controller_name.'.php', "a") or die("unable open file!"); $controller_content ="<?php defined('basepath') or exit('no direct script access allowed'); class $class_name extends my_controller { public function __construct() { parent::__construct(); } public function index() { \$this->data['site_title'] = '$page_name'; \$this->twig->display('$page_name',\$this->data); } }"; fwrite($controller, "\n". $controller_content); fclose($controller); // create model $model = fopen(apppath.'models/'.$class_name.'_model'.'.php', "a") or die("unable open file!"); $model_content ="<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class ".$class_name."_model"." extends ci_model { function __construct() { // call model constructor parent::__construct(); } } "; fwrite($model, "\n". $model_content); fclose($model); // create twig page $page = fopen(apppath.'views/'.$page_name.'.twig', "a") or die("unable open file!"); $page_content ='{% extends "base.twig" %} {% block content %} <div class="row"> <div class="col-md-12"> <h1>to {{ site_title }}</h1> </div> <!-- /.col --> </div> {% endblock %}'; fwrite($page, "\n". $page_content); fclose($page); }
Comments
Post a Comment