Welcome Guest, Not a member yet? Register   Sign In
Best way to do this
#1

[eluser]Jagar[/eluser]
Hi everyone,

I'm currently working on a project for work that uses smarty, CI (of course).

In my admin section I have few tables that I need to edit/delete/and list, I have done two of the tables, but it seem that i"m repeating myself, and copying and pasting the code and doing little changes.

In my controller, I have a folder called admin where all the restricted code are listed, and in the admin folder I have files like

setting_province.php
setting_province_add.php
setting_province_edit.php

also
setting_eventtype.php
setting_eventtype_add.php
and so on,

this will be the same for 7 other tables.

I'm pretty sure there must be a better way to do this, but can't think of anything.

Also in my views folder, I have:

[Admin]
--[settings]
----[provinces]
-------add.htm
-------edit.htm
-------index.htm
-----[eventtype]
-------add.htm
-------edit.htm
-------index.htm

If anyone knows a better way to do this, please let me know.

Thanks
#2

[eluser]Jagar[/eluser]
[quote author="Jagar" date="1241733494"]
restricted code are listed, and in the admin folder I have files like
[/quote]

I meanted restricted pages are listed
#3

[eluser]squarebones[/eluser]
Why not put all the CRUD code into one controller and call one model to do all the data processing for the table? In the controller, each of the CRUD functions is a method function _edit(), function _add(), etc. In the model, there are corresponding CRUD functions that manipulate the data for the appropriate table. For instance, I have a members controller, members_m model (and members_v view file(s) to boot. It's much easier to keep track of all the functions affecting a single table with just a few files and you don't have to have a ton files open in your editor. This makes sense to me coming from a procedural programming background to the MVC model (and I think it's mentioned in the user guide as a sensible solution).

Anyway, that's my dos centavos worth of wise-dumb.

Thank you.
#4

[eluser]opel[/eluser]
I created a crud function but it seems messy, I will dig out the code. Square bones any chance of a sample of yours ?

Jagar, you shouldn't need Smarty with the CI template language and helpers. Smarty is really heavy on page load Sad
#5

[eluser]xwero[/eluser]
If you do the validation in the model you can use a single controller method for a single action
Code:
function edit()
{
   $model = $this->uri->segment(2).'_model';
   $this->load->model($model);
  
   if(count($_POST) > 0 && ($error = $this->$model->edit($this->uri->segment(3))) != true)
   {
       $data['msg'] = $error;
   }

   $data['item'] = $this->model->item($this->uri->segment(3));

   $this->load->view($this->uri->segment(2).'_form',$data);
}
#6

[eluser]Jagar[/eluser]
[quote author="squarebones" date="1241750139"]Why not put all the CRUD code into one controller and call one model to do all the data processing for the table? In the controller, each of the CRUD functions is a method function _edit(), function _add(), etc. In the model, there are corresponding CRUD functions that manipulate the data for the appropriate table. For instance, I have a members controller, members_m model (and members_v view file(s) to boot. It's much easier to keep track of all the functions affecting a single table with just a few files and you don't have to have a ton files open in your editor. This makes sense to me coming from a procedural programming background to the MVC model (and I think it's mentioned in the user guide as a sensible solution).

Anyway, that's my dos centavos worth of wise-dumb.

Thank you.[/quote]

That gives me an idea, I will try that and see what happens.

Thank you
#7

[eluser]Jagar[/eluser]
[quote author="Opel" date="1241797157"]I created a crud function but it seems messy, I will dig out the code. Square bones any chance of a sample of yours ?

Jagar, you shouldn't need Smarty with the CI template language and helpers. Smarty is really heavy on page load Sad[/quote]

My whole site is in smarty, since this is intranet and not many people will be using it, I won't worry about performance too much. Smarty is good because it keeps the template clean like {$smarty_variable}.
#8

[eluser]opel[/eluser]
I am probably just bias our old work system uses smarty and i hate it...




Theme © iAndrew 2016 - Forum software by © MyBB