Filter Records on Distant Association
Hi All, So I'm a bit stuck on the above and I keep getting an sql server error. Yes I'm using mssql server :| - not my database. A little background, my relationships concerned look like this: AssetMaintenanceRecord->(belongs to)->Asset->(belongs to)->Project->(has one)->ProjectManager (note ProjectManager is like an alias model for a personnel table. The project table has an id for ProjectManager which is just the personnel id. So I'm trying to do a simple filter whereby I select all the AssetMaintenanceRecords by a search on ProjectManager. The related index function in AssetMaintenanceRecordsController.php looks like: public function index() { > $conditions = NULL; > if (isset($this->params['url']['report']) && > $this->params['url']['report'] == 'open') { > $conditions[] = array('CompletedDate' => NULL); > } > > if (isset($this->params['url']['report']) && > $this->params['url']['report'] == 'notified') { > $conditions[] = array('NotifiedDate BETWEEN ? AND ?' => > array(date('M d Y g:iA', strtotime($this->params['url']['datefrom'])), > date('M d Y g:iA', strtotime($this->params['url']['dateto']; > } > > if (isset($this->params['url']['report']) && > $this->params['url']['report'] == 'completed') { > $conditions[] = array('CompletedDate BETWEEN ? AND ?' => > array(date('M d Y g:iA', strtotime($this->params['url']['datefrom'])), > date('M d Y g:iA', strtotime($this->params['url']['dateto']; > } > > if (isset($this->params['url']['project'])) { > $conditions[] = array('Asset.aCurrProject' => > $this->params['url']['project']); > } > > if (isset($this->params['url']['ptCode']) && > $this->params['url']['ptCode'] != NULL) { > $conditions[] = array('Asset.ptCode' => > $this->params['url']['ptCode']); > } > > if (isset($this->params['url']['asset']) && > $this->params['url']['asset'] != NULL) { > $conditions[] = array('Asset.aFullCode' => > $this->params['url']['asset']); > } > > if (isset($this->params['url']['pm']) && > $this->params['url']['pm'] != NULL) { > $pm_search_terms = explode(' ', $this->params['url']['pm']); > foreach($pm_search_terms as $pm_search_term) { > $conditions[] = array( > 'OR' => array( > 'ProjectManager.PerGivenName LIKE' > =>'%'.$pm_search_term.'%', > 'ProjectManager.PerSurname LIKE' > =>'%'.$pm_search_term.'%', > ) > ); > } > } > > $this->paginate['AssetMaintenanceRecord'] = array( > 'contain' => array( > 'Asset' => array( > 'Project' => array( > 'ProjectManager' > )) > ), > 'order' => 'CompletedDate ASC', > 'limit' => 10 > ); > > $planttype = > $this->AssetMaintenanceRecord->Asset->PlantType->find('list'); > $this->set(compact('planttype')); > $this->AssetMaintenanceRecord->recursive = -1; > $this->set('records', $this->paginate('AssetMaintenanceRecord', > $conditions)); > } > Without the ProjectManager filter it works fine and I can echo out the ProjectManager array etc. but when I enter in a search term I get this error: The multi-part identifier "ProjectManager.PerSurname" could not be bound. > The executed sql looks like: 'SELECT TOP 10 [AssetMaintenanceRecord].[MtceRegID] AS > [AssetMaintenanceRecord__0], [AssetMaintenanceRecord].[AssetID] AS > [AssetMaintenanceRecord__1], > CAST(CAST([AssetMaintenanceRecord].[MtceRegNote] AS VARCHAR(8000)) AS TEXT) > AS [AssetMaintenanceRecord__2], [AssetMaintenanceRecord].[POno] AS > [AssetMaintenanceRecord__3], > CAST(CAST([AssetMaintenanceRecord].[NotifiedDate] AS VARCHAR(8000)) AS > TEXT) AS [AssetMaintenanceRecord__4], > CAST(CAST([AssetMaintenanceRecord].[CompletedDate] AS VARCHAR(8000)) AS > TEXT) AS [AssetMaintenanceRecord__5], > [AssetMaintenanceRecord].[MtceRegTitle] AS [AssetMaintenanceRecord__6], > CAST(CAST([AssetMaintenanceRecord].[CreatedDate] AS VARCHAR(8000)) AS TEXT) > AS [AssetMaintenanceRecord__7], [AssetMaintenanceRecord].[CreatedUserID] AS > [AssetMaintenanceRecord__8], > CAST(CAST([AssetMaintenanceRecord].[ModifiedDate] AS VARCHAR(8000)) AS > TEXT) AS [AssetMaintenanceRecord__9], > [AssetMaintenanceRecord].[ModifiedUserID] AS [AssetMaintenanceRecord__10], > [Asset].[aID] AS [Asset__11], [Asset].[ptCode] AS [Asset__12], > [Asset].[aNo] AS [Asset__13], [Asset].[aFullCode] AS [Asset__14], > [Asset].[aDesc] AS [Asset__15], [Asset].[aMake] AS [Asset__16], > [Asset].[aModel] AS [Asset__17], [Asset].[aSerialNo] AS [Asset__18],
Re: CakePHP (2.1) Media Plugin - Multi File Upload
Just thought I'd post my slightly cleaner solution to this which makes use of a modified version of the attachments element in the media plugin. This allows you to use the attachment multiple times in a form for when you have different groups of attachments i.e. photos, files, videos etc. I'm no programmer, just a designer so there's probably a better way to do it but I don't know it :) To save me editing too much I'll just use my example of a ProjectProfile model: ProjectProfile.php > array( 'className' => 'Project', 'foreignKey' => 'pjID' //'conditions' => '', //'fields' => '', //'order' => '' ) ); var $hasMany = array( 'Photo' => array( 'className' => 'Media.Attachment', 'order' => 'Photo.basename, Photo.id', 'foreignKey' => 'foreign_key', 'conditions' => array('Photo.model' => 'ProjectProfile', 'Photo.group' => 'Photo'), 'dependent' => true), 'Attachment' => array( 'className' => 'Media.Attachment', 'order' => 'Attachment.basename, Attachment.id', 'foreignKey' => 'foreign_key', 'conditions' => array('Attachment.model' => 'ProjectProfile', 'Attachment.group' => 'Attachment'), 'dependent' => true) ); } ProjectProfilesControler.php > ProjectProfile->id = $id; if (!$this->ProjectProfile->exists()) { throw new NotFoundException(__('Invalid project profile')); } if ($this->request->is('post') || $this->request->is('put')) { //convert cakephp html5 file upload data array to media plugin required format $model = Inflector::classify($this->params['controller']); foreach ($this->request->data[$model]['assocAlias'] as $assocAlias) { $i = 0; foreach ($this->request->data[$model][$assocAlias.'files'] as $file) { $this->set($this->request->data[$assocAlias][$i]['model'] = $model); $this->set($this->request->data[$assocAlias][$i]['group'] = strtolower($assocAlias)); $this->set($this->request->data[$assocAlias][$i]['file'] = $this->request->data[$model][$assocAlias.'files'][$i]); $i++; } } if ($this->ProjectProfile->saveAll($this->request->data)) { $this->Session->setFlash(__('The project profile has been saved')); $this->redirect(array('action' => 'admin_edit', $id)); } else { $this->Session->setFlash(__('The project profile could not be saved. Please, try again.')); } } else { $this->request->data = $this->ProjectProfile->read(null, $id); } $projects = $this->ProjectProfile->Project->find('list', array('fields' => array('Project.pjID', 'Project.pntitle'))); $this->set(compact('projects')); } ?> Then in the view/form: admin_edit.php > Form->create('ProjectProfile', array('type'=>'file'));?> Form->input('id'); echo $this->Form->input('pjID', array('label' => 'Project', 'options' => $projects)); echo $this->Form->input('description'); echo $this->Form->input('longitude'); echo $this->Form->input('latitude'); echo $this->Form->input('major', array('label' => 'Major Project')); //The num variable below is just used in the media attachments element so the controller can loop through the array, so just make sure you give each of the nums a sequential numerical order. The assocAlias just sets the group of attachments. echo $this->element('Media.attachments', array('model' => 'ProjectProfile', 'assocAlias' => 'Photo', 'num' => 0)); echo $this->element('Media.attachments', array('model' => 'ProjectProfile', 'assocAlias' => 'Attachment', 'num' => 1)); ?> Form->end(__('Submit'));?> Then this is a slightly modified version of the media attachment element, replace with this version... /Plugin/Media/View/Elements/attachment.php Media) || !is_a($this->Media, 'MediaHelper')) { $message = 'Attachments Element - The media helper is not loaded but required.';
Re: CakePHP (2.1) Media Plugin - Multi File Upload
Well this whole project has made me realise how much I suck at Ajax/JS etc. I ended up getting this working using cakephp's HTML5 multi file support and converting that data array to one that the media plugin would understand (as per Jeremy's first suggestion!). In case anybody else is looking to do this... In the view add to your form: echo $this->Form->input('files.', array('type' => 'file', 'multiple')); So that'll allow you to select multiple files. In the controller do something like: $i = 0; foreach ($this->request->data['Model']['files'] as $file) { $this->set($this->request->data['Photo'][$i]['model'] = 'Model'); $this->set($this->request->data['Photo'][$i]['group'] = 'group'); $this->set($this->request->data['Photo'][$i]['file'] = $this->request- >data['Model']['files'][$i]); $i++; } Then make sure you have saveAll: if ($this->Model->saveAll($this->request->data)) { ... I'm going to spend some time sorting it out better and making it as reusable as possible. This solution is good for me as it's for an intranet site so I have control over what browser people are using. And if the users's browser doesn't support html5 then they can still upload, just one file at a time. Thanks for your suggestions Jeremy. On May 1, 11:27 pm, jeremyharris wrote: > I don't have any templates, but I use file-uploader[1] on a currently > active project. It doesn't require jQuery but works pretty nicely. > > It sends each upload as a separate request, so write the controller code as > if you're receiving one file (like the media plugin examples) and you > should be good. This method is preferred, because when javascript is > disabled the logic in the controller doesn't need to change will still work > (i.e., old school single upload). > > 1:https://github.com/valums/file-uploader (doesn't seem to be maintained > by the author but there are numerous forks) > > > > > > > > On Monday, April 30, 2012 8:09:33 PM UTC-7, double07 wrote: > > Hi Jeremy, > > > Not having much luck with the saving manually option, do you having > > any working examples of drag and drop (jquery) I can look at? > > > Thanks, > > > -Brett > > > On Apr 17, 7:44 am, jeremyharris wrote: > > > > Or, instead of using the multiple option, you can try processing them > > each > > > as a single request so you don't have to change anything in your > > controller > > > but rather just how the view presents it. I've used drag and drop jQuery > > > plugins and the like to help with this. It's by far my favorite > > solution, > > > because it doesn't rely on browser specific features (such as HTML5 > > > multiple upload). -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: CakePHP (2.1) Media Plugin - Multi File Upload
Hi Jeremy, Not having much luck with the saving manually option, do you having any working examples of drag and drop (jquery) I can look at? Thanks, -Brett On Apr 17, 7:44 am, jeremyharris wrote: > > Or, instead of using the multiple option, you can try processing them each > as a single request so you don't have to change anything in your controller > but rather just how the view presents it. I've used drag and drop jQuery > plugins and the like to help with this. It's by far my favorite solution, > because it doesn't rely on browser specific features (such as HTML5 > multiple upload). > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: CakePHP (2.1) Media Plugin - Multi File Upload
Sorry I never got notified of replies for some reason, I will try this looping method I think it could work. Thanks! On Apr 17, 7:44 am, jeremyharris wrote: > You could try looping through the files array and saving them manually: > > foreach $_FILES['files'] as $file { > // create data array containing fields such as a foreignKey, model, etc. > and save them as individual records > > } > > Or, instead of using the multiple option, you can try processing them each > as a single request so you don't have to change anything in your controller > but rather just how the view presents it. I've used drag and drop jQuery > plugins and the like to help with this. It's by far my favorite solution, > because it doesn't rely on browser specific features (such as HTML5 > multiple upload). > > > > > > > > On Sunday, April 15, 2012 5:42:25 PM UTC-7, double07 wrote: > > > Hi All, > > > I'm using the cakephp media plugin in my project using the monolithic > > style attachments table, i.e. all the attachments go in the one table > > with foreign_key, model, group etc. saved with the file details. So my > > model looks like: > > > class ProjectProfile extends AppModel { > > > var $name = 'ProjectProfile'; > > var $useDbConfig = 'default'; > > var $useTable = 'project_profiles'; > > var $actsAs = array('Media.Transfer', 'Media.Generator'); > > > public $belongsTo = array( > > 'Project' => array( > > 'className' => 'Project', > > 'foreignKey' => 'pjID' > > ) > > ); > > > var $hasMany = array( > > 'Photo' => array( > > 'className' => 'Media.Attachment', > > 'order' => 'Photo.basename, Photo.id', > > 'foreignKey' => 'foreign_key', > > 'conditions' => array('Photo.model' => 'ProjectProfile', > > 'Photo.group' => 'Photo'), > > 'dependent' => true) > > ); > > > Then a saveAll in the controller when saving my record saves the > > attached file(s). > > > This all works fine, however I'd really like to be able to upload > > multiple files at once, which the plugin does support by doing this in > > the form: > > > echo $this->Form->hidden('Photo.0.model', array('value' => 'Photo')); > > echo $this->Form->input('Photo.0.file', array('type' => 'file'); > > echo $this->Form->hidden('Photo.1.model', array('value' => 'Photo')); > > echo $this->Form->input('Photo.1.file', array('type' => 'file'); > > echo $this->Form->hidden('Photo.2.model', array('value' => 'Photo')); > > echo $this->Form->input('Photo.2.file', array('type' => 'file'); > > > But I think you'd agree that's a bit cumbersome to have to click > > browse for each individual file. The simplist method I could see to to > > allow multiple file uploads was to use the HTML5 multiple file section > > option - > >http://bakery.cakephp.org/articles/veganista/2012/01/31/html_5_multip... > > : > > > echo $this->Form->input('files.', array('type' => 'file', > > 'multiple')); > > > This allows you to shift click in the file browser to select multiple > > files then puts the files into an array to save... however, this field > > format isn't handled by the media plugin. Also, there'd be no way to > > add the model, group etc. fields on the save as far as I could see. > > > So, does anybody know how I can handle multi file uploads with the > > media plugin using the monolithic model? I'm open to all suggestions. > > > Thanks in advance. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
CakePHP (2.1) Media Plugin - Multi File Upload
Hi All, I'm using the cakephp media plugin in my project using the monolithic style attachments table, i.e. all the attachments go in the one table with foreign_key, model, group etc. saved with the file details. So my model looks like: class ProjectProfile extends AppModel { var $name = 'ProjectProfile'; var $useDbConfig = 'default'; var $useTable = 'project_profiles'; var $actsAs = array('Media.Transfer', 'Media.Generator'); public $belongsTo = array( 'Project' => array( 'className' => 'Project', 'foreignKey' => 'pjID' ) ); var $hasMany = array( 'Photo' => array( 'className' => 'Media.Attachment', 'order' => 'Photo.basename, Photo.id', 'foreignKey' => 'foreign_key', 'conditions' => array('Photo.model' => 'ProjectProfile', 'Photo.group' => 'Photo'), 'dependent' => true) ); Then a saveAll in the controller when saving my record saves the attached file(s). This all works fine, however I'd really like to be able to upload multiple files at once, which the plugin does support by doing this in the form: echo $this->Form->hidden('Photo.0.model', array('value' => 'Photo')); echo $this->Form->input('Photo.0.file', array('type' => 'file'); echo $this->Form->hidden('Photo.1.model', array('value' => 'Photo')); echo $this->Form->input('Photo.1.file', array('type' => 'file'); echo $this->Form->hidden('Photo.2.model', array('value' => 'Photo')); echo $this->Form->input('Photo.2.file', array('type' => 'file'); But I think you'd agree that's a bit cumbersome to have to click browse for each individual file. The simplist method I could see to to allow multiple file uploads was to use the HTML5 multiple file section option - http://bakery.cakephp.org/articles/veganista/2012/01/31/html_5_multiple_file_upload_with_cake : echo $this->Form->input('files.', array('type' => 'file', 'multiple')); This allows you to shift click in the file browser to select multiple files then puts the files into an array to save... however, this field format isn't handled by the media plugin. Also, there'd be no way to add the model, group etc. fields on the save as far as I could see. So, does anybody know how I can handle multi file uploads with the media plugin using the monolithic model? I'm open to all suggestions. Thanks in advance. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: HABTM pagination issue
Actually, I found when I did it with the above code I lost all my existing relationships which caused problems. I worked out a better way: $this->News->bindModel(array('hasOne' => array('NewsVenue')), false); $this->set(array('news' => $this->paginate('News', array ('NewsVenue.venue_id' => 1; Hope that helps somebody. On Oct 12, 10:35 am, double07 wrote: > Thanks for pointing me in the right direction. > > For some reason $this->paginate('RolesUser'); didn't work by itself, > but after having the same issue later in the project the solution was: > (where News hasandbelongstomany Venue) > > $this->News->NewsVenue->bindModel(array('belongsTo' => array('News', > 'Venue')), false); //the false is important here, apparently it stops > the queries being reset when using pagination > $this->set(array('news' => $this->paginate('NewsVenue', array > ('NewsVenue.venue_id' => 1; > > Cheers. > > On Sep 16, 5:03 am, Miles J wrote: > > > To paginate withHABTM, you must use theHABTMmodel. > > > $this->paginate('RolesUser'); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Custom Route + Param breaks Pagination
Hi All, I've got a custom route which points to a sub-controller: Router::connect('/happyvalley/news/:action/*', array('controller' => 'happyvalley_news', 'prefix' => 'happyvalley', 'happyvalley' => true)); It all works fairly well except for when I add a custom parameter, in this case 'q' (which is a search query) it completely breaks pagination and the next/previous links show something like: / happyvalley_news/happyvalley_index/page:2/q:test/happyvalley:1 So I did my research and found I should put something like this in my view: $paginator->options(array('url' => array_merge($this->passedArgs, array ('happyvalley' => true; Again It all works perfectly until my custom param gets in there. Anybody have any ideas? TIA -Brett PS... thought I better include the two controller functions: function happyvalley_index() { $options['conditions'] = array('News.publish' => 1, 'NewsVenue.venue_id' => 1); if (isset($this->passedArgs['q'])) { $input = $this->passedArgs['q']; $q = $input; $options['conditions'] = array( "MATCH(News.title,News.body) AGAINST('$q' IN BOOLEAN MODE)", array('News.publish' => 1, 'NewsVenue.venue_id' => 1)); } $this->News->recursive = 2; $this->News->NewsVenue->bindModel(array('belongsTo' => array('News', 'Venue')), false); $this->set(array('news' => $this->paginate('NewsVenue', $options ['conditions']))); $this->layout = 'default_happyvalley'; $this->viewPath = 'news/happyvalley'; } function happyvalley_results() { if (($this->params['url']['q']) <> NULL) { $input = $this->params['url']['q']; $q = $input; $this->redirect(array('happyvalley' => TRUE, 'action'=>'happyvalley_index'.'/q:'.$q), null, true); } $this->redirect(array('happyvalley' => TRUE, 'action'=>'happyvalley_index'), null, true); $this->layout = 'default_happyvalley'; $this->viewPath = 'news/happyvalley'; } The form in the view just posts to "happyvalley_results" which is then redirected to the index. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM pagination issue
Thanks for pointing me in the right direction. For some reason $this->paginate('RolesUser'); didn't work by itself, but after having the same issue later in the project the solution was: (where News hasandbelongstomany Venue) $this->News->NewsVenue->bindModel(array('belongsTo' => array('News', 'Venue')), false); //the false is important here, apparently it stops the queries being reset when using pagination $this->set(array('news' => $this->paginate('NewsVenue', array ('NewsVenue.venue_id' => 1; Cheers. On Sep 16, 5:03 am, Miles J wrote: > To paginate withHABTM, you must use theHABTMmodel. > > $this->paginate('RolesUser'); > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
HABTM pagination issue
Hi All, I'm having an issue with using HABTM with pagination... My app has a users and roles table - users HABTM roles, roles have many users. In my users index controller I'm trying to limit the pagination results so that only users with certain roles are displayed. At the moment I have: $this->User->recursive = 1; $this->set('users', $this->paginate('User', array('Roles.name' => 'Administrator'))); This gives me this error: Warning (512): SQL Error: 1054: Unknown column 'Roles.name' in 'where clause' [CORE\cake\libs\model\datasources\dbo_source.php, line 525] When I do pretty much the same this with a 'find all' it seems to work ok: $this->set('data', $this->User->Role->find('all', array ('conditions'=>array('Role.name'=>'Administrator'; Where am I going wrong here? TIA --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Multiple prefixes and reverse prefix routing
I'm nearly there folks. My solution has been to modify the 'controller' part of my links in my views to include /venue/controller and /admin/venue/controller. This works fine in the non admin links i.e. /venue/controller/action/id - and partially works for admin i.e. / admin/venue/controller - but as soon as I add on an id or something it breaks i.e. /admin/venue/users/view/1 doesn't work but /admin/venue/ users does. I get the error: Error: VenueController could not be found. Where Venue = the name of the venue - there actually is a venue controller but I'm using generic terms here. My routes currently look like this: Router::connect('/venue', array('controller' => 'pages', 'action' => 'display', 'venue_home', 'venue' => true)); Router::connect('/venue/pages/*', array('controller' => 'pages', 'action' => 'display', 'venue' => true)); Router::connect('/venue/:controller/:action/*', array('prefix' => 'venue', 'venue' => true)); Router::connect('/admin/venue', array('controller' => 'pages', 'action' => 'display', 'admin_venue_home', 'admin_venue' => true)); Router::connect('/admin/venue/:controller/:action', array('prefix' => 'admin_venue', 'admin_venue' => true)); Note I also have the builtin cake admin routes activated. Any ideas anyone? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Multiple prefixes and reverse prefix routing
Hi all, I'm having trouble with getting my routes setup for a project I'm working on. See this thread for a little more background on the project: http://groups.google.com/group/cake-php/browse_thread/thread/33544e08936fba4e/069109e06b3fca09?lnk=gst&q=a+better+way#069109e06b3fca09 Basically it has a main site, then sub-sites for the various venues. So I'm wanting to setup prefixes for the venues and use them in conjunction with the built in admin prefix routing. For example, I'd like the url to look like: http://site/venue/controller/action Which is easily setup, however I'd also like to use the admin prefix with this i.e.: http://site/admin/venue/controller/action or http://site/venue/admin/controller/action I don't really care which way around Now this all works fine except when I use the html helper to create links, all links revert to: http://site/controller/action So following the manual I add: 'venue' => true to the link Which works fine for the non admin route but on the admin route the links revert to something like: http://site/users/view/1/admin_venue:1 using this code: echo $html- >link(__('View', true), array('admin_venue' => true, 'controller' => 'users', 'action'=>'view', $user['User']['id'], )); My routes look like this: Router::connect('/venue', array('controller' => 'pages', 'action' => 'display', 'venue_home', 'venue' => true)); Router::connect('/venue/:controller/:action/*', array('controller' => 'users', 'prefix' => 'venue', 'venue' => true)); Router::connect('/admin/venue/:controller/:action', array('prefix' => 'admin_venue', 'admin_venue' => true)) What am I doing wrong here? Thanks in advance for any tips. -Brett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: A better way? Grouping controllers and views
Hi again. I just need some more clarification on this issue. I like the idea of setting up named parameters for the venues in the routes. However, I'm using an ACL system where users can be restricted by controllers and actions. If I understand correctly the named parameters would allow me to do some simple logic in one single controller (i.e. limit the find query's to a single venue).So if I'm only using one controller how can I apply the ACL rules to users/ groups? At the moment I have some groups setup for the venues so that somebody from Venue1 can't edit the news etc from Venue2. Perhaps I need to keep the sub controllers separate after all? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: A better way? Grouping controllers and views
Thnaks for the feedback Mark & Martin, I'll have a look at these options over the next couple of days and see how they work out. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
A better way? Grouping controllers and views
Hi All, I'm working on a project at the moment which has a main site then sub sites for venue franchises. The venue sub sites are effectively the same as the main site but the news items etc are filtered to be only for that particular venue. The way I have this setup at the moment is as follows (I'll use news as an example): -Just a standard news model -a main controller for news news_controller.php -a sub controller for each venue i.e. venue1_news_controller.php - this is the same as the normal news controller except it has a condition to filter only news items for 'venue1' -normal news views -a venue1 sub folder in news containing slightly different views (mainly to add a hidden venue id field when adding news so when a venue1 editor can only add news for venue1) - accessed in the venue1 news controller via changing the view path -Then I have routes setup ie: Router::connect('/venue1/news/:action/ *', array('controller' => 'venue1_news')); Now this all works perfectly fine. However, what concerns me is the amount of times I'm effectively repeating things which are - bar a few small differences - doing essentially the same thing. Also, if I have to make changes to the news controller I effectively have to update each sub controller too. I'm just wondering if this is the best way to go about things? Is there a better way where I could have only one news controller/set of views but somehow add the conditions for the venues on the fly or something? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: $ajax->editor help
Works like a charm, thank you for suggesting that link. I might put a comment in the manual as it doesn't seem to mention: $this->params['form']['value'] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How much to donate to CakePHP???
I generally donate $10 everytime I download cakephp from the website. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
$ajax->editor help
Hi All, I'm currently working on a comments section of my site and I'm trying to allow the comments to be edited via an ajax edit-in-place field. I can't work out how the data is passed to the controller though and also how to access that data in the controller... In my controller I have: function admin_edit() { $this->Comment->saveField('body', ???); $this->set('comment', ??? ); $this->layout = 'ajax'; } In my view I have: echo '' . $comment['body'] . ''; echo $ajax->editor( 'Comment'.$comment['id'], array( 'controller' => 'comments', 'action' => 'admin_edit', $comment['id'] ), array('okText' => 'Save', 'rows' => '4', 'cols' => '72', 'highlightcolor' => '#d1eeff', 'highlightendcolor' => '#f4f4f4') ); echo ''; In the submitted view I have: I can't work out what I'm supposed to put where the question marks are. In my searching high and low for an answer I came across a similar post on these groups saying that the data is available in the controller via $this->params['formname']['field'] - so does this mean that I have to put the $ajax->editor inside a form? If not how do I know what the ajax form/field is named??? Thanks, -Brett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination of search results
Thanks for your input Martin, but I ended up going a slightly different way... Basically I decided to use a custom named parameter which in the end looks pretty tidy. So if anyone is interested, this is what I did: In my news controller: function admin_index() { $options['conditions'] = array(); if (isset($this->passedArgs['q'])) { $input = $this->passedArgs['q']; App::import('Sanitize'); $q = Sanitize::escape($input); $options['conditions'] = array( "MATCH(News.title,News.body) AGAINST('$q' IN BOOLEAN MODE)" ); } $this->News->recursive = 0; $this->set(array('news' => $this->paginate('News', $options['conditions']))); } The top of my view file looks like this: options(array('url' => $this->passedArgs)); ?> create('news', array('type' => 'get', 'controller' => 'admin/news', 'action' => 'results')); echo $form->input('q', array('label' => '', 'size' => '35'));?> params['named']['q'])) { echo "Search Results for ".$this->params['named']['q'].""; } ?> It basically submits the form to another controller function called "admin_results". This function is very simple and just grabs the "q" variable from the query string and converts it to a named parameter: function admin_results() { if (($this->params['url']['q']) <> NULL) { $input = $this->params['url']['q']; App::import('Sanitize'); $q = Sanitize::escape($input); $this->redirect(array('action'=>'admin_index'.'/q:'.$q), null, true); } $this->redirect(array('action'=>'admin_index'), null, true); } That's pretty much it, works like a charm. Not sure if it's the most elegant way. If I knew of a way to get the named param into the url straight out of the form I could skip the "admin_results" redirect function. -Brett On Sep 19, 11:37 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Like you say this has been discussed quite a bit before. > The way I was advised to do this (which works really well) is to > "POST" (or GET) thesearchto a proxy-action that creates a nice url > that paginator will play nice with and redirects you to ourresults. > > Example: > function lookup() > { > if ( !empty($this->params['url']['q']) ) > { > $param = $this->params['url']['q']; > $this->redirect('lookupResults/'.$param); > return; > }else{ > // do something else here > } > > } > > This function would look for a GET parameter called q and redirect you > to /controller/lookupResults/test or something similar. This will then > be able to play nice with paginator if you add this to your view: > $paginator->options(array('url' => $this->passedArgs)); > > your next button would go to: /controller/lookupResults/test/page:2 > > double07 wrote: > > Hi all, > > > I know there's a lot of info around on this already but I haven't been > > able to solve this issue myself. > > > I'm just setting up a simplesearchwhich will trawl through the > > titles and bodies of news items. > > > I borrowed some code from the bakery here: > >http://bakery.cakephp.org/articles/view/paginating-with-fulltext-sear... > > > I made a few minor changes but it's more or less the same > > > in my news controller: > > function admin_search() { > > $this->News->recursive = 1; > > $conditions = array(); > > > if (isset($this->params['url']['q'])) { > > > $input = $this->params['url']['q']; > > > App::import('Sanitize'); > > $q = Sanitize::escape($input); > > > $options['conditions'] = > > array("MATCH(News.title,News.body) > > AGAINST('$q'
Pagination of search results
Hi all, I know there's a lot of info around on this already but I haven't been able to solve this issue myself. I'm just setting up a simple search which will trawl through the titles and bodies of news items. I borrowed some code from the bakery here: http://bakery.cakephp.org/articles/view/paginating-with-fulltext-searches I made a few minor changes but it's more or less the same in my news controller: function admin_search() { $this->News->recursive = 1; $conditions = array(); if (isset($this->params['url']['q'])) { $input = $this->params['url']['q']; App::import('Sanitize'); $q = Sanitize::escape($input); $options['conditions'] = array("MATCH(News.title,News.body) AGAINST('$q' IN BOOLEAN MODE)"); } $this->set(array('results' => $this->paginate('News', $options['conditions']))); } In the bakery article they just had: $this->set(array('results' => $this->paginate('News', $options))); But that wouldn't work for me? So according to the manual to pass the query string to the paginator I just put this line of code at the top of my view: options(array('url' => $this->passedArgs)); ?> So it works as in it returns the first page of results (via /admin/ news/search?q=test) but when I hover over the next/back/page number/ filter links it doesn't pass on the search query string it just looks like: /admin/news/search/page:2 If I manually enter a query string it works perfectly i.e. /admin/news/ search/page:2?q=test Any ideas why the querystring isn't being used by the paginator? TIA. -Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Echo Fields of Article Ceator/Modifer in View
Got this sorted if anybody was interested, my use of foreignKey was wrong... News Model: var $belongsTo = array ('Creator' => array( 'className' => 'User', 'foreignKey' => 'creator_id', ), 'Modifier' => array( 'className' => 'User', 'foreignKey' => 'modifier_id', ), ); To echo out in the view: That simple! Thanks for your input James! On Jul 11, 8:13 am, double07 <[EMAIL PROTECTED]> wrote: > So the News items should "Belong To" a user. The problem I see is that > you can't seem to define a "local key"? > > My code in the News controller should look like this yeah? > > var $belongsTo = array('Creator' => array( > 'className' => 'User', > 'foreignKey' => 'user_id', > 'localKey' => 'creator_id', > //can't seem to define this? > ), > 'Modifier' => array( > 'className' => 'User', > 'foreignKey' => 'user_id', > 'localKey' => 'modifer_id', > //can't seem to define this? > ), > > ); > > How can I define the local key? > > On Jul 9, 10:02 pm, James K <[EMAIL PROTECTED]> wrote: > > > You would need to define a relationship in your news model to the > > user's model via the id set by the behaviour. This will tell cake how > > to pull the related models from a find call on the news model (http:// > > book.cakephp.org/view/66/models#associations-linking-models-to-78). > > > You'll also want to look in the manual for more information on the new > > containable behaviour built into the release candidates of CakePHP 1.2 > > for how to narrow down what fields/models you want returned (http:// > > book.cakephp.org/view/474/containable) > > > Good luck, > > > - James > > > On Jul 9, 12:26 am, double07 <[EMAIL PROTECTED]> wrote: > > > > Hi All, > > > > This seems like a real n00b question, but here goes. I'm working on an > > > app which has articles - in my case news - and users who create/modify > > > the news articles. Now I found this nifty little behaviour > > > -http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-r... > > > - which automagically records the user id in the news record when > > > somebody adds or edits a news item. So I've got the user id of the > > > creator/modifier in the news article record... lovely. > > > > So, how then do I use that id in the creator/modifer to grab say the > > > name/email/username of the user and echo it out in a view? At first I > > > was thinking it would be a relationship, but now I'm thinking I need > > > to do something in the news controller? > > > > If anyone could point me in the right direct that would be much > > > appreciated. Any examples would be helpful. > > > > TIA. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Echo Fields of Article Ceator/Modifer in View
So the News items should "Belong To" a user. The problem I see is that you can't seem to define a "local key"? My code in the News controller should look like this yeah? var $belongsTo = array('Creator' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'localKey' => 'creator_id', //can't seem to define this? ), 'Modifier' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'localKey' => 'modifer_id', //can't seem to define this? ), ); How can I define the local key? On Jul 9, 10:02 pm, James K <[EMAIL PROTECTED]> wrote: > You would need to define a relationship in your news model to the > user's model via the id set by the behaviour. This will tell cake how > to pull the related models from a find call on the news model (http:// > book.cakephp.org/view/66/models#associations-linking-models-to-78). > > You'll also want to look in the manual for more information on the new > containable behaviour built into the release candidates of CakePHP 1.2 > for how to narrow down what fields/models you want returned (http:// > book.cakephp.org/view/474/containable) > > Good luck, > > - James > > On Jul 9, 12:26 am, double07 <[EMAIL PROTECTED]> wrote: > > > Hi All, > > > This seems like a real n00b question, but here goes. I'm working on an > > app which has articles - in my case news - and users who create/modify > > the news articles. Now I found this nifty little behaviour > > -http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-r... > > - which automagically records the user id in the news record when > > somebody adds or edits a news item. So I've got the user id of the > > creator/modifier in the news article record... lovely. > > > So, how then do I use that id in the creator/modifer to grab say the > > name/email/username of the user and echo it out in a view? At first I > > was thinking it would be a relationship, but now I'm thinking I need > > to do something in the news controller? > > > If anyone could point me in the right direct that would be much > > appreciated. Any examples would be helpful. > > > TIA. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Echo Fields of Article Ceator/Modifer in View
Hi All, This seems like a real n00b question, but here goes. I'm working on an app which has articles - in my case news - and users who create/modify the news articles. Now I found this nifty little behaviour - http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-record-creator-and-modifier-in-cakephp-12/ - which automagically records the user id in the news record when somebody adds or edits a news item. So I've got the user id of the creator/modifier in the news article record... lovely. So, how then do I use that id in the creator/modifer to grab say the name/email/username of the user and echo it out in a view? At first I was thinking it would be a relationship, but now I'm thinking I need to do something in the news controller? If anyone could point me in the right direct that would be much appreciated. Any examples would be helpful. TIA. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Ajax form won't submit
I should also add to this that the ajax link doesn't seem to work in IE7 either. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Ajax form won't submit
Woh, what happened there! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Ajax form won't submit
Hi all, This is doing my head in so I'm posting here as a last resort. I'm reasonably new to cakephp, I've written a simple CMS app last year but I'm working on a new v1.2.0.6311 project now with user management/acl built in. Basically I'm working on the user management area at the moment specifically a reset password function. Now it's not practical to have the password field in the "edit user" form because it's not something I wan't admins to accidentally change. So I've got the edit user form setup with an ajax link to the reset password action. The ajax link in the edit form looks like this: echo $ajax->link('Reset Password', '/users/resetPassword/'.$form- >value('User.id'), array('update' => 'ResetPassword'), null, FALSE); So when I click on that the "ResetPassword" div is updated with the reset_password.ctp view which looks like this: form(array('action' => '/users/resetPassword'), 'post', array('update' => 'resetPassword'));?> Reset Password hidden('username'); echo $form->input('password', array('type' => 'password', 'value' => '')); ?> submit('Reset Password', array('url'=>'/users/ resetPassword')); ?> So I enter a new password and hit "Reset Password"... ... ... nothing. The resetPassword section of my users controller looks like this: function resetPassword($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash('Invalid User'); $this->redirect(array('action'=>'index'), null, true); } if (!empty($this->data)) { $this->cleanUpFields(); if ($this->User->save($this->data)) { $this->Session->setFlash('The password has been reset'); } else { $this->Session->setFlash('The password could not be reset. Please, try again.'); } } if (empty($this->data)) { $this->data = $this->User->read(null, $id); } } The top of my users controller looks like this: var $name = 'Users'; var $helpers= array('Html', 'Form', 'Javascript', 'Ajax'); var $components = array('InheritAcl', 'RequestHandler'); Any ideas where I'm going wrong here? I'm really having difficulty finding any simple ajax form tutorials for v1.2. The form works perfectly without ajax. FYI firebug reports an error in prototype.js on line 2239 "element has no properties" _observeAndCache(null, "submit", function(), false)prototype.js (line 2239) observe(null, "submit", function(), false)prototype.js (line 2266) evalScripts("\n//
Re: Kae's filemanager - FCKeditor - $_SERVER['DOCUMENT_ROOT'] problem
Nevermind, got this sorted out. On Aug 21, 9:02 am, double07 <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm trying to configure Kae's filemanager (http://kfm.verens.com/) for > FCKeditor and I'm having a problem with cake. You can see my post over > at the KFM forums (http://kfm.verens.com/phpBB3/viewtopic.php? > f=2&t=152) that the developer is saying $_SERVER['DOCUMENT_ROOT'] is > not returning a path. On my testing server at home it works fine but > on my production server I'm getting the errors. Also on a non cake > site on the same server KFM works fine. > > Is anybody familiar with these apps/plugins and does anyone know what > could be causing this? > > TIA - Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Kae's filemanager - FCKeditor - $_SERVER['DOCUMENT_ROOT'] problem
Hi all, I'm trying to configure Kae's filemanager (http://kfm.verens.com/) for FCKeditor and I'm having a problem with cake. You can see my post over at the KFM forums (http://kfm.verens.com/phpBB3/viewtopic.php? f=2&t=152) that the developer is saying $_SERVER['DOCUMENT_ROOT'] is not returning a path. On my testing server at home it works fine but on my production server I'm getting the errors. Also on a non cake site on the same server KFM works fine. Is anybody familiar with these apps/plugins and does anyone know what could be causing this? TIA - Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Global css navigation menu from DB
So I'm having a crack at using a component. My component (nav.php) looks like this: class NavComponent extends Object { var $menu = null; function doNav() { $this->menu = "testing"; //just for testing purposes } } In my app_controller.php I have: class AppController extends Controller { var $uses = array('Node'); var $components = array('othAuth', 'nav'); // necessary, we need to have the othauth component so it can do it's business logic var $helpers = array('Html', 'OthAuth', 'Tree'); // html is always needed, othauth helper is not a must, but you can do some cool things with it (see later on) var $othAuthRestrictions = array( 'add','edit','delete'); // these are the global restrictions, they are very important. all the permissions defined above are weighted against these restrictions to calculate the total allow or deny for a specific request. function beforeFilter() { $this->nav->doNav(); //call the component here $auth_conf = array( 'mode' => 'oth', 'login_page' => '/users/login', 'logout_page' => '/users/logout', 'access_page' => '/', 'hashkey' => 'MySEcEeTHaSHKeYz', 'noaccess_page' => '/users/noaccess', 'strict_gid_check' => false); $this->othAuth->controller = &$this; $this->othAuth->init($auth_conf); $this->othAuth->check(); } } When I try to refer to the $menu variable in my layout (echo $menu;) I get this error: Notice: Undefined variable: menu in C:\wamp\www\cake\app\views\layouts \default.thtml on line 19 Any ideas? Am I even heading in the right direction? Thanks again. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Global css navigation menu from DB
I still get this error: Notice: Undefined property: PagesController::$Node in C:\wamp\www\cake \app\app_controller.php on line 51 Fatal error: Call to a member function findAllThreaded() on a non- object in C:\wamp\www\cake\app\app_controller.php on line 51 I tried it in \app and \app\controllers and it didn't work in either. Tulio... sorry but I'm a bit of a n00b, how would I go about setting the navigation up in a component? Thanks. On Apr 21, 4:24 am, Tulio Faria <[EMAIL PROTECTED]> wrote: > In this case, I prefer to create a component and use it in the > AppController. > > I have a lot of problems with $uses in AppController, and the only way > I found to around this was using component. > > Best, > > On 18 abr, 10:22, Andrew McCafferty <[EMAIL PROTECTED]> > wrote: > > > Firstly, the $name of AppController isn't "Nodes" so remove that > > line... > > > Try replacing it with: > > > var $uses = array('Node'); > > > This should tell AppController to use your Node model, making the > > findAllThreaded function available. > > > On 18 Apr, 06:17, double07 <[EMAIL PROTECTED]> wrote: > > > > Hi All, > > > > I'm trying to setup aglobalcssnavigation menu. Basically All my > > > pages for the site are in a table called 'nodes'. Each page has a > > > parent_id so I can use findAllThreaded() to generate an unordered list > > > using a 'tree' helper (http://bakery.cakephp.org/articles/view/64) I > > > found in the bakery. > > > > Now when I set this up in a specific function within the Nodes > > > controller it works fine. example: > > > > In the function 'edit' within the nodes controller I have this bit of > > > code: > > > $this->set('category_tree', $this->Node->generateList()); > > > > In my default layout page I have: > > > echo $tree->show('Node/title', $menu); > > > > Obviously this only works when I'm in - /nodes/edit/x > > > > What I want is to have that navigation available on every single page > > > so I don't have to set the menu variable in each function in each > > > controller. From my research around the place it seems that using > > > beforeFilter() in AppController is what I'm looking for, but I'm not > > > sure my syntax is correct as I get this error: > > > Notice: Undefined property: PagesController::$Node in C:\wamp\www\cake > > > \cake\app_controller.php on line 64 > > > Fatal error: Call to a member function findAllThreaded() on a non- > > > object in C:\wamp\www\cake\cake\app_controller.php on line 64 > > > > In my app_controller.php file I have: > > > > class AppController extends Controller { > > > > var $name = 'Nodes'; > > > var $components = array('othAuth'); > > > var $helpers = array('Html', 'OthAuth'); > > > var $othAuthRestrictions = array( 'add','edit','delete'); > > > > function beforeFilter() > > > { > > > > $this->set('menu', $this->Node->findAllThreaded()); //This is > > > the line in question > > > > $auth_conf = array( > > > 'mode' => 'oth', > > > 'login_page' => '/users/login', > > > 'logout_page' => '/users/logout', > > > 'access_page' => '/', > > > 'hashkey' => 'MySEcEeTHaSHKeYz', > > > 'noaccess_page' => '/users/noaccess', > > > 'strict_gid_check' => false); > > > > $this->othAuth->controller = &$this; > > > $this->othAuth->init($auth_conf); > > > $this->othAuth->check(); > > > > } > > > > } > > > > Could somebody please give me some pointers or tell me if I'm on the > > > right track. If not are there any suggestions to achieve what I'm > > > trying to do? > > > > 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Global css navigation menu from DB
Hi Andrew, I tried what you suggested, unfortunately I still get the error mentioned above. Cheers. On Apr 18, 10:22 pm, Andrew McCafferty <[EMAIL PROTECTED]> wrote: > Firstly, the $name of AppController isn't "Nodes" so remove that > line... > > Try replacing it with: > > var $uses = array('Node'); > > This should tell AppController to use your Node model, making the > findAllThreaded function available. > > On 18 Apr, 06:17, double07 <[EMAIL PROTECTED]> wrote: > > > Hi All, > > > I'm trying to setup aglobalcssnavigation menu. Basically All my > > pages for the site are in a table called 'nodes'. Each page has a > > parent_id so I can use findAllThreaded() to generate an unordered list > > using a 'tree' helper (http://bakery.cakephp.org/articles/view/64) I > > found in the bakery. > > > Now when I set this up in a specific function within the Nodes > > controller it works fine. example: > > > In the function 'edit' within the nodes controller I have this bit of > > code: > > $this->set('category_tree', $this->Node->generateList()); > > > In my default layout page I have: > > echo $tree->show('Node/title', $menu); > > > Obviously this only works when I'm in - /nodes/edit/x > > > What I want is to have that navigation available on every single page > > so I don't have to set the menu variable in each function in each > > controller. From my research around the place it seems that using > > beforeFilter() in AppController is what I'm looking for, but I'm not > > sure my syntax is correct as I get this error: > > Notice: Undefined property: PagesController::$Node in C:\wamp\www\cake > > \cake\app_controller.php on line 64 > > Fatal error: Call to a member function findAllThreaded() on a non- > > object in C:\wamp\www\cake\cake\app_controller.php on line 64 > > > In my app_controller.php file I have: > > > class AppController extends Controller { > > > var $name = 'Nodes'; > > var $components = array('othAuth'); > > var $helpers = array('Html', 'OthAuth'); > > var $othAuthRestrictions = array( 'add','edit','delete'); > > > function beforeFilter() > > { > > > $this->set('menu', $this->Node->findAllThreaded()); //This is > > the line in question > > > $auth_conf = array( > > 'mode' => 'oth', > > 'login_page' => '/users/login', > > 'logout_page' => '/users/logout', > > 'access_page' => '/', > > 'hashkey' => 'MySEcEeTHaSHKeYz', > > 'noaccess_page' => '/users/noaccess', > > 'strict_gid_check' => false); > > > $this->othAuth->controller = &$this; > > $this->othAuth->init($auth_conf); > > $this->othAuth->check(); > > > } > > > } > > > Could somebody please give me some pointers or tell me if I'm on the > > right track. If not are there any suggestions to achieve what I'm > > trying to do? > > > 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Global css navigation menu from DB
Hi All, I'm trying to setup a global css navigation menu. Basically All my pages for the site are in a table called 'nodes'. Each page has a parent_id so I can use findAllThreaded() to generate an unordered list using a 'tree' helper (http://bakery.cakephp.org/articles/view/64) I found in the bakery. Now when I set this up in a specific function within the Nodes controller it works fine. example: In the function 'edit' within the nodes controller I have this bit of code: $this->set('category_tree', $this->Node->generateList()); In my default layout page I have: echo $tree->show('Node/title', $menu); Obviously this only works when I'm in - /nodes/edit/x What I want is to have that navigation available on every single page so I don't have to set the menu variable in each function in each controller. From my research around the place it seems that using beforeFilter() in AppController is what I'm looking for, but I'm not sure my syntax is correct as I get this error: Notice: Undefined property: PagesController::$Node in C:\wamp\www\cake \cake\app_controller.php on line 64 Fatal error: Call to a member function findAllThreaded() on a non- object in C:\wamp\www\cake\cake\app_controller.php on line 64 In my app_controller.php file I have: class AppController extends Controller { var $name = 'Nodes'; var $components = array('othAuth'); var $helpers = array('Html', 'OthAuth'); var $othAuthRestrictions = array( 'add','edit','delete'); function beforeFilter() { $this->set('menu', $this->Node->findAllThreaded()); //This is the line in question $auth_conf = array( 'mode' => 'oth', 'login_page' => '/users/login', 'logout_page' => '/users/logout', 'access_page' => '/', 'hashkey' => 'MySEcEeTHaSHKeYz', 'noaccess_page' => '/users/noaccess', 'strict_gid_check' => false); $this->othAuth->controller = &$this; $this->othAuth->init($auth_conf); $this->othAuth->check(); } } Could somebody please give me some pointers or tell me if I'm on the right track. If not are there any suggestions to achieve what I'm trying to do? 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: CMS: How to set pages to have 'parents'?
Still wrestling with this issue. Managed to contact the author of the script and they re-wrote it a bit, but still no joy for me. See comments here: http://othy.wordpress.com/2006/06/03/generatenestedlist/ The generateNestedList() function just produces an empty variable. I did notice in debug mode that I'm getting an SQL error. Some how the function is trying to query the database with the string 'generateNestedList'. Just to re-cap what I've got in my app: --In the app controller file I've got the snippet from othy which includes the generateNestedList() function - http://othy.wordpress.com/2006/06/03/generatenestedlist/ --In my Model I've just got: class Node extends AppModel { var $name = 'Node'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'NodeType' => array('className' => 'NodeType', 'foreignKey' => 'node_type_id', 'counterCache' => '' ), ); } --In my Controller (for the edit function) I've got: function edit($id = null) { if(empty($this->data)) { if(!$id) { $this->Session->setFlash('Invalid id for Node'); $this->redirect('/nodes/index'); } $this->data = $this->Node->read(null, $id); $this->set('nodeTypes', $this->Node->NodeType->generateList()); $this->set('category_tree', $this->Node->generateNestedList()); // <--this is the line in question } else { $this->cleanUpFields(); if($this->Node->save($this->data)) { $this->Session->setFlash('The Node has been saved'); $this->redirect('/nodes/index'); } else { $this->Session->setFlash('Please correct errors below.'); $this->set('nodeTypes', $this->Node->NodeType->generateList()); } } } --And in my view I've got: labelTag('Node/parent_id', 'Parent Id');?> selectTag('Node/parent_id', $category_tree, $html- >tagValue('Node/parent_id'), array(), array(), true) --My Nodes DB schema looks like this: http://housepimp.com/cake_nodes.gif Any help would be much appreciated. Thanks, Brett. On Mar 12, 8:26 pm, "double07" <[EMAIL PROTECTED]> wrote: > Using this in the controller: $this->set('category_tree', > $category_tree); > > Just produces this error: Undefined variable: category_tree in C:\wamp > \www\cake\app\controllers\nodes_controller.php on line 47 > > I think this is correct: $this->set('category_tree', > $this->Node->generateNestedList('--', > > null)); > > I have a similar bit of code in the same controller which seems to > work: > $this->set('nodeTypes', $this->Node->NodeType->generateList()); // in > the controller > > selectTag('Node/node_type_id', $nodeTypes, > $html->tagValue('Node/node_type_id'), array(), array(), true);?> // in the > > view > > The problem seems specific to the generateNestedList function, I just > can't work it out. The snippet from Othy is just to advanced for a > poor designer to understand ;( > > Cheers, > > Brett. > > On Mar 12, 8:16 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > > > $this->set('category_tree', $category_tree); //in the controller, so the > > view can use the variable... > > > HTH, > > Eric > > > On 3/11/07, double07 <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > I just wanted to re-visit this again. I've come back after a couple of > > > weeks break to attempt to finish this project, in particular the > > > 'parent' select list which needs to be indented (for ease of use). Now > > > I found what I thought was the perfect bit of code by 'Othy' here: > > >http://othy.wordpress.com/2006/06/03/generatenestedlist/ > > > > It's supposed to generate nested lists for use with select/drop downs. > > > It
Re: CMS: How to set pages to have 'parents'?
Using this in the controller: $this->set('category_tree', $category_tree); Just produces this error: Undefined variable: category_tree in C:\wamp \www\cake\app\controllers\nodes_controller.php on line 47 I think this is correct: $this->set('category_tree', $this->Node- >generateNestedList('--', null)); I have a similar bit of code in the same controller which seems to work: $this->set('nodeTypes', $this->Node->NodeType->generateList()); // in the controller selectTag('Node/node_type_id', $nodeTypes, $html- >tagValue('Node/node_type_id'), array(), array(), true);?> // in the view The problem seems specific to the generateNestedList function, I just can't work it out. The snippet from Othy is just to advanced for a poor designer to understand ;( Cheers, Brett. On Mar 12, 8:16 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > $this->set('category_tree', $category_tree); //in the controller, so the > view can use the variable... > > HTH, > Eric > > On 3/11/07, double07 <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I just wanted to re-visit this again. I've come back after a couple of > > weeks break to attempt to finish this project, in particular the > > 'parent' select list which needs to be indented (for ease of use). Now > > I found what I thought was the perfect bit of code by 'Othy' here: > >http://othy.wordpress.com/2006/06/03/generatenestedlist/ > > > It's supposed to generate nested lists for use with select/drop downs. > > It's a bit light on the documentation and I'm having trouble getting > > it to work. > > > As per the instructions, in my app_controller.php file I put the > > following code: > > >function generateNestedList($indent = ' ',$sort = null) > >{ > >$this->recursive = '-1'; > >$cats = $this->findAllThreaded(null, > > array($this->name.'.id',$this- > > >name.'.name',$this->name.'.parent_id'), $sort); > >$glist = $this->_generateNestedList($cats,$indent); return > > $glist; > >} > >function _generateNestedList($cats,$indent,$level = 0) > >{ > >static $list = array(); > >for($i = 0, $c = count($cats); $i < $c; $i++) > >{ > >$list[$cats[$i][$this->name]['id']] = > > str_repeat($indent,$level). > > $cats[$i][$this->name]['name']; if(isset($cats[$i]['children']) && ! > > empty($cats[$i]['children'])) > >{ > > > $this->_generateNestedList($cats[$i]['children'],$indent,$level + > > 1); > >} > >} > >return $list; > >} > > > Now in my controller (called Nodes) I've got: > > > $this->set('category_tree', $this->Node->generateNestedList('--', > > null)); > > > This seems correct and doesn't produce any errors, however when I try > > to use the category_tree in a selectTag in my view, I get nothing: > > > selectTag('Node/parent_id', $category_tree, $html- > > >tagValue('Node/parent_id'), array(), array(), true);?> > > > If I just print_r $category tree, it's also empty. > > > Has anybody got experience with this snippet of code by Othy (I'd ask > > him directly but there doesn't seem to be any contact info on his > > page)? Or could somebody please give me some pointers??? Alternatively > > another method would be appreciated. > > > Thanks again, > > > Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: CMS: How to set pages to have 'parents'?
Hi all, I just wanted to re-visit this again. I've come back after a couple of weeks break to attempt to finish this project, in particular the 'parent' select list which needs to be indented (for ease of use). Now I found what I thought was the perfect bit of code by 'Othy' here: http://othy.wordpress.com/2006/06/03/generatenestedlist/ It's supposed to generate nested lists for use with select/drop downs. It's a bit light on the documentation and I'm having trouble getting it to work. As per the instructions, in my app_controller.php file I put the following code: function generateNestedList($indent = ' ',$sort = null) { $this->recursive = '-1'; $cats = $this->findAllThreaded(null, array($this->name.'.id',$this- >name.'.name',$this->name.'.parent_id'), $sort); $glist = $this->_generateNestedList($cats,$indent); return $glist; } function _generateNestedList($cats,$indent,$level = 0) { static $list = array(); for($i = 0, $c = count($cats); $i < $c; $i++) { $list[$cats[$i][$this->name]['id']] = str_repeat($indent,$level). $cats[$i][$this->name]['name']; if(isset($cats[$i]['children']) && ! empty($cats[$i]['children'])) { $this->_generateNestedList($cats[$i]['children'],$indent,$level + 1); } } return $list; } Now in my controller (called Nodes) I've got: $this->set('category_tree', $this->Node->generateNestedList('--', null)); This seems correct and doesn't produce any errors, however when I try to use the category_tree in a selectTag in my view, I get nothing: selectTag('Node/parent_id', $category_tree, $html- >tagValue('Node/parent_id'), array(), array(), true);?> If I just print_r $category tree, it's also empty. Has anybody got experience with this snippet of code by Othy (I'd ask him directly but there doesn't seem to be any contact info on his page)? Or could somebody please give me some pointers??? Alternatively another method would be appreciated. Thanks again, Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: CMS: How to set pages to have 'parents'?
Success! Yes I admit :) I just copied the code from Eric without checking it (I'm a cake n00b with a design background - not much php/programming). Just needed to refer to the 'Node' model and change around a few other things and I managed to get the array out. Then I used the tree helper to convert it to a unordered list and it's working perfectly. Now the rest is just details, I just need to work out how to get it into a drop down and that's about it. Thanks for all your help people. On Feb 26, 10:47 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > Um...should be a method of the model > class:http://api.cakephp.org/class_model.html#181aefe1bf7efe1504692c485c83caa8http://api.cakephp.org/1.2/classModel.html#181aefe1bf7efe1504692c485c... > > Are you calling it as $this->Node->findAllThreaded(...), as in the example > in your first post? > > Eric > > On 2/26/07, double07 <[EMAIL PROTECTED]> wrote: > > > > > Firstly, thanks for your feedback, but I'm getting this error? > > > Fatal error: Call to undefined method stdClass::findAllThreaded() in C: > > \wamp\www\cake\app\controllers\nodes_controller.php on line 45 > > > Am I missing something here? > > > Cheers. > > > On Feb 24, 1:30 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > > > The following helped me when I was setting up something like this: > > > > $this->Category->recursive = 0; > > > $this->set('category_tree', $this->Category->findAllThreaded(null, > > > array('id','parent_id','name'),'parent_id, name')); > > > > It'll give you a multidimensional array based on parent_id. You could > > also > > > use something like this to find parent nodes of an article. > > > > HTH, > > > Eric --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: How to set pages to have 'parents'?
Thanks Mariano, I'll have a look at that component once I get the array Eric mentioned up and running. Cheers. On Feb 24, 1:34 pm, "Mariano Iglesias" <[EMAIL PROTECTED]> wrote: > Sounds like findAllThreaded() is the answer you are looking for: > > http://bakery.cakephp.org/articles/view/63 > > Also check the component I wrote here, as it solves something typical in > threaded models (finding the breadcrumb): > > http://groups.google.ch/group/cake-php/browse_thread/thread/6c7cdd0cc... > #c6b957972849d439 > > I can't give you the link on standard google groups website since strangely > lots of the archives on groups.google.com are no longer there, and can only > be find through google groups mirrors. > > -MI > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: CMS: How to set pages to have 'parents'?
Firstly, thanks for your feedback, but I'm getting this error? Fatal error: Call to undefined method stdClass::findAllThreaded() in C: \wamp\www\cake\app\controllers\nodes_controller.php on line 45 Am I missing something here? Cheers. On Feb 24, 1:30 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > The following helped me when I was setting up something like this: > > $this->Category->recursive = 0; > $this->set('category_tree', $this->Category->findAllThreaded(null, > array('id','parent_id','name'),'parent_id, name')); > > It'll give you a multidimensional array based on parent_id. You could also > use something like this to find parent nodes of an article. > > HTH, > Eric > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
CMS: How to set pages to have 'parents'?
Ok, this is doing my head in. Basically I'm trying to setup a simple CMS. So the part I'm wrestling with here is the pages or what I've called 'Nodes' Now my nodes basically have fairly simple fields; id, parent_id, title, summary, body, node_type_id, link, members and publish. It's all pretty much setup and ready to go except for the parent/ navigation... My plan was that there would be a navigation menu that would be dynamically generated from the nodes table by setting it up so that each node can be a child of another page (or it could be at the top of the 'tree' by being 0). When editing/adding a page, the idea would be that the user could just select the parent from a drop down list (which has indented menu options). Now, I can't for the life of me work out how to go about this in cake (i.e. models, relationships etc.). In hindsight it might have been easier to setup "sections" that could be edited/added and then generate the menu from that, but in the past I've found that setup can cause problems. Has anyone successfully setup anything similar to what I want? If so, could you please give me some pointers. Thanks in advance, Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
obAuth Errors
Hi all, I'm new to Cake and I come more from a design background... so be gentle :) I trying to setup the obAuth component - http://bakery.cakephp.org/ articles/view/121 Whenever I try to secure certain actions in my controllers ($this- >obAuth->lock(array(2));), I get an error similar to this: Notice: Undefined property: NewsController::$obAuth in C:\wamp\www\cake \app\controllers\news_controller.php on line 21 Fatal error: Call to a member function lock() on a non-object in C: \wamp\www\cake\app\controllers\news_controller.php on line 21 If I try to get into the login view I get this error: Fatal error: Class 'UsersController' not found in C:\wamp\www\cake\cake \dispatcher.php on line 155 This is my setup: in: /app/controllers/components - I have the component code in a file named ob_auth.php <-- is that the correct naming convention? I've tried all other combinations I can think of i.e. obAuth.php, ob_Auth.php, ob_auth_component etc. I have a users controller as per the tutorial I have a model for 'user' and 'group' with the relationships setup as described. Can anybody give me some pointers here??? Thanks in advance. -Brett. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---