Using _remap()
- Posted by dlib on March 26th, 2008 filed in Code examples, Tutorials
To try some things out last night I used the _remap() method in my controller. It might be the beginning of an admin or scaffold panel but I’m not sure yet whether it’s gonna be developed entirely so that’s why I show you what I’ve got right now.
Anyway, it demonstrates quite nicely how you can use the _remap() method.
It also demonstrates usage of ORM and the Model to Form class (Model_Formation).
class Scaffold_Controller extends Controller{ protected $model; public function _remap($model,$arguments) //first argument is the normally the method, the second an array of arguments { $this->model=$model; if(!isset($arguments[0])) { $arguments[0]='overview'; } $method=array_shift($arguments); call_user_func_array(array($this,$method),$arguments); } public function overview() { $list=ORM::factory($this->model)->find_all(); foreach($list as $row) { $row=array_slice($row->as_array(),0,3); //only show first three fields foreach($row as $field) { echo $field .' - '; } echo '<br>'; } } public function edit($id) { $id=(int) $id; $form=new Model_Formation(ORM::factory($this->model)->find($id)); //give a model with id=$id, if($form->save()) { echo 'saved'; } else { echo 'not saved'; } echo $form; } public function insert() { $form=new Model_Formation(ORM::factory($this->model)); //give an empty ORM model if($form->save()) { echo 'saved'; } else { echo 'not saved'; } echo $form; } }
So, how does this work. The _remap() method is present which means that normal dispatching to the controller methods is cancelled and it’s up to _remap() to handle it. The _remap() changes the normal behaviour so what’s normally the controller method now becomes the model scaffolding works for. The first argument now is the method which will be used. The index() method is not present but if no method is given ‘overview’ is used.
Let’s try out a few urls:
- http://localhost/scaffold/article - will call the overview method and show the first three fields of the article model
- http://localhost/scaffold/article/overview - like the above
- http://localhost/scaffold/article/edit/5 - Will show a filled form from the database for the article model
- http://localhost/scaffold/article/insert - Will show an empty form for the article model
- http://localhost/scaffold/comment/insert - Will show an empty form for the comment model
That’s how you could use the _remap() method to override the default dispatching.
You can also see how the Model_Formation accepts an ORM model and converts it into a form, filled or not. The overview() method could of course also use a grid class to show a proper table.
I hope I’ve demonstrated well how you can use the _remap() method to alter behaviour of the dispatcher. If you have any questions, let me know.
free viagra
buy viagra online
generic viagra
how does viagra work
cheap viagra
buy viagra
buy viagra online inurl
viagra 6 free samples
viagra online
viagra for women
viagra side effects
female viagra
natural viagra
online viagra
cheapest viagra prices
herbal viagra
alternative to viagra
buy generic viagra
purchase viagra online
free viagra without prescription
viagra attorneys
free viagra samples before buying
buy generic viagra cheap
viagra uk
generic viagra online
try viagra for free
generic viagra from india
fda approves viagra
free viagra sample
what is better viagra or levitra
discount generic viagra online
viagra cialis levitra
viagra dosage
viagra cheap
viagra on line
best price for viagra
free sample pack of viagra
viagra generic
viagra without prescription
discount viagra
gay viagra
mail order viagra
viagra inurl
generic viagra online paypal
generic viagra overnight
generic viagra online pharmacy
generic viagra uk
buy cheap viagra online uk
suppliers of viagra
how long does viagra last
viagra sex
generic viagra soft tabs
generic viagra 100mg
buy viagra onli
generic viagra online without prescription
viagra energy drink
cheapest uk supplier viagra
viagra cialis
generic viagra safe
viagra professional
viagra sales
viagra free trial pack
viagra lawyers
over the counter viagra
best price for generic viagra
viagra jokes
buying viagra
viagra samples
viagra sample
cialis
generic cialis
cheapest cialis
buy cialis online
buying generic cialis
cialis for order
what are the side effects of cialis
buy generic cialis
what is the generic name for cialis
cheap cialis
cialis online
buy cialis
cialis side effects
how long does cialis last
cialis forum
cialis lawyer ohio
cialis attorneys
cialis attorney columbus
cialis injury lawyer ohio
cialis injury attorney ohio
cialis injury lawyer columbus
prices cialis
cialis lawyers
viagra cialis levitra
cialis lawyer columbus
online generic cialis
daily cialis
cialis injury attorney columbus
cialis attorney ohio
cialis cost
cialis professional
cialis super active
how does cialis work
what does cialis look like
cialis drug
viagra cialis
cialis to buy new zealand
cialis without prescription
free cialis
cialis soft tabs
discount cialis
cialis generic
generic cialis from india
cheap cialis sale online
cialis daily
cialis reviews
cialis generico
how can i take cialis
cheap cialis si
cialis vs viagra
levitra
generic levitra
levitra attorneys
what is better viagra or levitra
viagra cialis levitra
levitra side effects
buy levitra
levitra online
levitra dangers
how does levitra work
levitra lawyers
what is the difference between levitra and viagra
levitra versus viagra
which works better viagra or levitra
buy levitra and overnight shipping
levitra vs viagra
canidan pharmacies levitra
how long does levitra last
viagra cialis levitra
levitra acheter
comprare levitra
levitra ohne rezept
levitra 20mg
levitra senza ricetta
cheapest generic levitra
levitra compra
cheap levitra
levitra overnight
levitra generika
levitra kaufen
June 17th, 2008 at 2:03 pm
I have found and using a cms found on google code that uses this type of _remap() and it works great. However, how would I bypass this remap for a certain uri? So, for a certain URI, I would like it to access the controller named the same as the segment. Any help would be appreciated
June 19th, 2008 at 10:39 am
[...] method. There are already ways to change how the controller method calling works. Having a _remap() method can change the functionality of the controller completely for example. Or the _default() method, [...]