> But just for the future, is there any article/discussion about > including controllers functions inside others? > Thats a tipical case and I wanted to read more about it.
I don't think so, but I could be wrong. Here's a brief overview of your options for sharing logic between controllers: * If it's app-global or almost, but it in AppController. * If it's used by some but not most of the controllers, stick the logic in a Component * Use requestAction (if you really really need to) * Try something like this : http://www.thinkingphp.org/2006/06/24/welcome-to-the-dark-side-of-plugins-in-cakephp/ But in a large number of cases, the extra / shared logic shouldn't be in the controller. It should be in the model. I've got fully-functioning applications where most of the controllers are empty stubs, because the generic handling in AppController [learnt that from AD7six, I was amazed at how much repetitive code could be slashed with this approach] , and the bulk of the logic code in the model [or behaviors], means they just aren't necessary. On Feb 12, 2:34 pm, MX <[EMAIL PROTECTED]> wrote: > Man I loved that solution. Also because it gives me a global solution. > Thanks! > > But just for the future, is there any article/discussion about > including controllers functions inside others? > Thats a tipical case and I wanted to read more about it. > > On Feb 12, 2:05 pm, grigri <[EMAIL PROTECTED]> wrote: > > > This is just an idea: > > > app/controllers/app_controller.php > > > class AppController extends Controller { > > > function redirect($url, $status = null, $exit = true) { > > if (is_array($url)) { > > $url['inline'] = !empty($this->params['named']['inline']); > > } > > return parent::url($url, $status, $exit); > > } > > > function beforeFilter() { > > if (!empty($this->params['named']['inline'])) { > > // Set layout > > $this->layout = 'simple'; > > } > > } > > > } > > > (alternatively, if you don't need this logic in every controller, put > > it in a component and implement beforeRedirect()) > > > app/views/helpers/app_helper.php > > > class AppHelper extends Helper { > > function url($url = null, $full = false) { > > if (is_array($url)) { > > $url['inline'] = !empty($this->namedArgs['inline']); > > } > > return parent::url($url, $full); > > } > > > } > > > On Feb 12, 1:28 pm, MX <[EMAIL PROTECTED]> wrote: > > > > I think I wrote too much and explained so little. > > > This is the situation: > > > > 3 Backend Controllers: > > > - Users > > > - News > > > - Images > > > > news/admin_add.ctp > > > __________________ > > > > ... > > > <link: array('controller' => 'image', 'action' => 'index', 'inline' => > > > true)> > > > ... > > > > images_controller.php > > > ____________________ > > > > class ImagesController extends AppController > > > { > > > public function beforeFilter() > > > { > > > if (isset($this->params['named']['inline'])) > > > { > > > $this->layout = 'simple'; > > > } > > > } > > > > public function admin_upload() > > > { > > > ... > > > $this->redirect(array('action' => 'edit', $uploaded_file_name, > > > 'inline' => isset($this->params['named']['inline'])); > > > } > > > > } > > > > That is just a snip, but EVERY redirection on the controller needs > > > that confirmation to make the option persistente between navigation. > > > The same for all the views of the images. > > > > I think I am clear now. The problem now is that I need to pass another > > > variable because I have multiple editors and need to pass the ID. > > > > I have already thinked in elements, but the problem is that this is a > > > COMPLETE controller. Also elements would still need this logic, > > > to persist these options on the URL. > > > > What can I do? : ( > > > > On Feb 12, 9:49 am, grigri <[EMAIL PROTECTED]> wrote: > > > > > I might be completely off here, but when I need to differentiate > > > > between popups, ajax dialogs, flash messages and "normal" pages, I use > > > > exactly the same view but change the layout. The layout also specifies > > > > what css to include so the entire look of the view can be changed > > > > without much effort. > > > > > On Feb 12, 5:32 am, Adam Royle <[EMAIL PROTECTED]> wrote: > > > > > > I'm not sure I understand fully what you are trying to do, however why > > > > > can't you use normal variables to determine this kind of behaviour? > > > > > eg. either swap the view based on the mode, or do if/else statements > > > > > in your view. > > > > > > Without more info (and a code example if you can) I can't really > > > > > suggest anything else. > > > > > > Adam > > > > > > On Feb 12, 2:41 pm, MX <[EMAIL PROTECTED]> wrote: > > > > > > > Hey, > > > > > > > Well I am coding this *simple* website which has users, articles and > > > > > > images. Its the simple scenary. > > > > > > It contains a front and backend all action-separated with proper > > > > > > "admin" pre-named. > > > > > > > The images controller offers the administrators the oportunity to > > > > > > list, upload, edit and delete the images. > > > > > > The interface is a simple CRUD. > > > > > > > But it comes to the point that I want to include an image (existing > > > > > > or > > > > > > new) to an Article. > > > > > > Not that matters but the rich editor triggers a popup which displays > > > > > > the Images options. > > > > > > > The problem comes here. Well right now I am playing with setting a > > > > > > "simpler" layout, by passing a condition on the URI: admin/images/ > > > > > > mode:inline. > > > > > > > But the problem is that I must update ALL links of the Images views, > > > > > > to "transport" the "mode" condition. > > > > > > So a link to admin/images/upload, must carry out the "mode:inline", > > > > > > if > > > > > > mode is present. > > > > > > This results in views being able to service both scenarios: accessed > > > > > > directly as a controller or by the popup. > > > > > > But this is not a clean solution, neither is readable (come across + > > > > > > 10 links, all with same code.) > > > > > > > What do you suggest? It would be fine (and not an hack, but an > > > > > > honest > > > > > > solution) if it was possible to mantain certain *persistent* > > > > > > conditions on the URI automaticly. > > > > > > > But I want an MVC (not just because its cool, but as a part of code > > > > > > organization/optimization) and this problem will be an example for > > > > > > future projects. > > > > > > > Hope you help, thanks in advance! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
