autocontrollers

#1
[eluser]jparent[/eluser]
I've worked with CI for 2 years and I love it. I do my own Controller and my own model. They help me to reduce a lot of code. Now I want to advance one more step. I want to make a generic controller that takes information from an XML file and configure automatically 5 basic pages:

- list : list all elements of the table
- detail: list one elemnt of the table
- insert/update: built a form for insert/update the element
- delete: delete one or many elements of the table

Additionally the XML reflects which is the controller's main model and which are the submodels. The submodels are models like related products, related links, ..., and when you define this models it genererate methods for:

- add relationship
- update relationship
- delete relationship

That now is only an idea. I want to refine it. Because I think this xml config file will became to bigger and I think i need one "site.xml" for general config and one xml file foreach controller. I don't know.

I think to use a config file like CI:

Code:
$config['param'] = 'value';

but I don't like this format for deep tree configuration like:
Code:
$config['site']['controller']['models']['submodel']['relationships']['has_many'] = 'value';

I like you and me share Ideas to make easy the configuration of sites, and if I (or We) could, develop a general purpose CMS. The idea is that with the same appliation we will can develep a blog or a ecommerce or both with only enable the right modules and change only few things.

Thanks, everybody!

#2
[eluser]pickupman[/eluser]
For whatever it's worth, someone has created a similar idea. However, it uses php at the command line and not email. It's called CrudIgniter, and you can generate these types of things. There are template files for a view, model, and controller. Then just call php ci project_name, and follow the prompts. Pretty simple. It took a little tweaking to get it work to my liking, but it provides a quick & dirty method to get some quick structure.

#3
[eluser]jparent[/eluser]
I don't want generate code I wan't that the controller works allways the same way based on a config file that says it who is his model or models and how to use it. Then, if you wan't a especific behaviour you overwrite a method or create it.

#4
[eluser]pickupman[/eluser]
Ah...I haven't tried it but it seems if you code it in the same ways as some of the core class this maybe possible. It would seem if you create a master controller with
Code:
if(!method_exists('some_method'){
   function some_method(){
     //Do stuff here
   }
}

Then when you create a parent controller, then child class can extend it. Take at look at this [url="http://www.philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY"]post[/url]. This might be on the track to take it to the next step for you.

#5
[eluser]jparent[/eluser]
I've thought in something like:

Code:
class MX_Controller extends Controller
{  
  function show_all($row = NULL,$howmany = NULL)
  {
      $model = $this->properties->get('main_model');
      $data['entries'] = $this->{$model}->get_all($row,$howmany);
      $this->_render('show_all');//joins all partial views with the 'show_all' view
  }
  //more methods like show_one show_by($field,$value),insert,update($id),delete
  ...
}

Then when you declare a controller it will be simple like:

Code:
class Blog extends MX_Controller
{
function __construct()
{
  parent::__construct();
  $this->porperties = load_properties('blog');
}
}

And you will have the basic methods, then you can do new ones or extend it. You will can change the view changing the theme in the properties.

This is a simple example. I might consider that it will have relationship tables, javascript, css, additional helpers or libraries ..., additional views, interacction between controllers...

#6
[eluser]pickupman[/eluser]
After reading some of the code in PyroCMS and a few other blogs, I have started putting table & field names in the constructor of my model and defining them in a config file. I have a template for my models, add the table/fields in the config, and away I go.

Check out more at this [url="http://shawnmccool.com/2009/08/28/how-to-write-a-better-model-in-code-igniter/"]blog[/url]. You can use it similar to how I need and add more to it to make it more dynamic.

#7
[eluser]jparent[/eluser]
Thank's that post is so interesting but I want more general model. In this post the model is programed for a concret model (Users). I want to declare the model users and only implements methos like 'get_ten_best_users()', for example. Only implement concret methods and forget to implement CRUD methods and forget to implement the navigation between relationships.

#8
[eluser]pickupman[/eluser]
What I have done is taken the model from the post and removed some of the static things like table 'users', and replaced with dynamic content. Remember models are still classes, so you can create an initialize/setter method, in which you could dynamically declare tables/fields.

#9
[eluser]jparent[/eluser]
Yeah, like datamapper. I have MY_Model in that way you've said. Now I'm trying to extend the controller. I want that you dont need to implement methods like 'list', 'create' , 'edit' or 'delete' (if you don't want to create a specific one) I want you only create the views and especific methods and the other will be authomatic.

#10
[eluser]pickupman[/eluser]
What I like about generating a template for MVC, is it seems inevitable that I always need another method for something specific in a model. Glad to hear you are making some progress.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.