sonoton345 Posted June 10, 2009 Share Posted June 10, 2009 I have a menu in cakePHP created using css and would like to change the color of the text when on a corresponding page. The menu is in default.ctp in the layout folder. Can anyone advice please? Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/ Share on other sites More sharing options...
ehutchison Posted June 11, 2009 Share Posted June 11, 2009 So if I understand you correctly.. I will assume you have a 'home' page and a 'about us' page. When your on the 'about us' page you want it to highlight the 'about us' link, and if on the 'home' page, you want it to highlight 'home' somehow? Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-853824 Share on other sites More sharing options...
sonoton345 Posted June 11, 2009 Author Share Posted June 11, 2009 That's correct.. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-853988 Share on other sites More sharing options...
jcombs_31 Posted June 12, 2009 Share Posted June 12, 2009 You can pass variables to the layout from the controller. So, in your about controller, you can have something like... function about() { // controller logic ... $this->set('page_for_layout', 'about'); ... } Then, depending on how your menu and css is set up, you can have something like this in your default.ctp <ul class="<?php echo $page_for_layout; ?>"> <li><a href='#'>Home</a></li> <li><a href='#'>About</a></li> </ul> In your css, you would have something like .home a { //some style } .about a { //some style } There are probably other ways, but I like this one. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-854738 Share on other sites More sharing options...
ehutchison Posted June 12, 2009 Share Posted June 12, 2009 I'm Ehutchison, and I approve this post. You can pass variables to the layout from the controller. So, in your about controller, you can have something like... function about() { // controller logic ... $this->set('page_for_layout', 'about'); ... } Then, depending on how your menu and css is set up, you can have something like this in your default.ctp <ul class="<?php echo $page_for_layout; ?>"> <li><a href='#'>Home</a></li> <li><a href='#'>About</a></li> </ul> In your css, you would have something like .home a { //some style } .about a { //some style } There are probably other ways, but I like this one. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-854768 Share on other sites More sharing options...
sonoton345 Posted June 14, 2009 Author Share Posted June 14, 2009 Thanks for this...but in my own case the 4 of the corresponding pages to the navigations are static pages. They are all in the pages folder so I didn't have to create a controller. How do I go with this? One other thing...Any idea why $form->month('mob') does not send the value of the month e.g January but sends an array to the database? I have a database error that shows the value being sent is Array Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-855428 Share on other sites More sharing options...
jcombs_31 Posted June 14, 2009 Share Posted June 14, 2009 You can set up the menu in an element and pass variables to the element from the view. The book can actually be quite useful. http://book.cakephp.org/view/97/Elements Can't really answer the form problem without seeing more of your code. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-855773 Share on other sites More sharing options...
sonoton345 Posted June 15, 2009 Author Share Posted June 15, 2009 Thank you for the menu tip, I'll look into that.... excerpts from the form code is this on the view side - registration.ctp <p><label>Title:<span class="required">*</span></label> <?php $options=array('Mr'=>'Mr','Mrs'=>'Mrs','Ms'=>'Ms'); e($form->select('title', $options,array('id'=>'tx'))); ?></p> <p><label>First Name:<span class="required">*</span></label><?php e($form->text('first_name', array('id'=>'txt'))); ?></p> <p><label>Last Name:<span class="required">*</span></label><?php e($form->text('last_name', array('id'=>'txt'))); ?></p> <p><label>Date Of Birth:<span class="required">*</span></label><?php e($form->month('mob',01)); e($form->day('dayborn',1)); e($form->year('yearborn',date('Y')-18, date('Y')-62,date('Y')-18)); <p><label>Address:<span class="required">*</span></label><?php e($form->text('address', array('id'=>'txt'))); ?></p> <p><label>Address 2:</label><?php e($form->text('address2', array('id'=>'txt'))); ?></p> <p><label>City:<span class="required">*</span></label><?php e($form->text('city', array('id'=>'txt'))); ?></p> <p><label>Zip Code:<span class="required">*</span></label><?php e($form->text('zip_code', array('id'=>'txt'))); ?></p> <p><label>Phone:<span class="required">*</span></label><?php e($form->text('phone', array('id'=>'txt'))); ?></p> <p><?php e($form->submit('Register',array('div'=>false,'class' =>'submitbutton'))) ?> <?php e($form->end()); ?> in my controller, I have this... function register() { if (!empty($this->data)) { $this->Jobseeker->create(); if ($this->Jobseeker->save($this->data)) { $this->Session->setFlash('Congratulations! You have signed up!'); $this->redirect(array('controller'=>'employers','action'=>'index')); } else { $this->Session->setFlash('There was an error signing up. Please try again.'); } } // set page title $this->pageTitle = 'iWeev - Registration'; // set layout file $this->layout = 'mytemp2'; } This is the sql error SQL Error: 1054: Unknown column 'Array' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 525] Query: INSERT INTO `jobseekers` (`status`, `username`, `password`, `title`, `first_name`, `last_name`, `mob`, `dayborn`, `yearborn`, `address`, `address2`, `city`, `zip_code`, `phone`, `modified`, `created`) VALUES ('0', 'olu@ymail.com', 'bad55116b77f7d180d4ba6b0c9732f2fdca73bab', 'Mr', 'Olu', 'Olus', Array, Array, Array, '1234 te', '', 'testing', 233444, '1233333333', '2009-06-14 23:14:14', '2009-06-14 23:14:14') Instead of sending the values of date,month and year, it's sending Array, Array, Array Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-856009 Share on other sites More sharing options...
jcombs_31 Posted June 16, 2009 Share Posted June 16, 2009 First, you should run debug on $this->data. The problem appears to be that you are passing extra parameters to the form helper that is doesn't understand. e($form->month('mob',01)); e($form->day('dayborn',1)); e($form->year('yearborn',date('Y')-18, date('Y')-62,date('Y')-18)); I don't know what 01 and 1 are doing in the month/day fields, and in year your should be passing min/max, you are sending 3 parameters. http://book.cakephp.org/view/204/Form-Element-Specific-Methods Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-856716 Share on other sites More sharing options...
sonoton345 Posted June 16, 2009 Author Share Posted June 16, 2009 Thanks, when I wrote those form elements I actually followed the documentation you wrote in your response. the 01 and 1 in month/day are selected values by default, so by default it selects January for month and 1 for date. In the year my min is [current year] -18 and max is [current year] - 62 ,which means the lowest age will always be 18 by year and highest age will always be 62 by year. The third parameter here also is the selected value by default. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-856810 Share on other sites More sharing options...
jcombs_31 Posted June 16, 2009 Share Posted June 16, 2009 I see, but selected should be a string so make sure you add some quotes around those values. Did you run debug on $this->data ? Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-857219 Share on other sites More sharing options...
sonoton345 Posted June 16, 2009 Author Share Posted June 16, 2009 I'm sorry, I'm a cakephp beginner How does one run debug? Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-857237 Share on other sites More sharing options...
sonoton345 Posted June 16, 2009 Author Share Posted June 16, 2009 from the cakephp doc it says debug($var, $showHTML = false, $showFrom = true) So it should be this? debug($this->data) Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-857246 Share on other sites More sharing options...
ehutchison Posted June 16, 2009 Share Posted June 16, 2009 correct, but be sure you have the debug level properly set. should be in app/config/core.php Configure::write('debug', 1); Using debug is similar to doing a print_r(); with <pre></pre> tags Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-857389 Share on other sites More sharing options...
sonoton345 Posted June 16, 2009 Author Share Posted June 16, 2009 Thanks once again. I removed all the extra parameters and this is what I got from using debug... Array ( [Jobseeker] => Array ( [username] => tester@ymail.com [password] => testers [password2] => testers [title] => Mr [first_name] => Tester1 [last_name] => Tester2 [mob] => Array ( [month] => 01 ) [dayborn] => Array ( [day] => 01 ) [yearborn] => Array ( [year] => 1991 ) [address] => 1234 rt [address2] => [city] => dfgg [zip_code] => 56788 [phone] => 2345566 ) ) This is the part of my form now that is returning Array... <p><label>Date Of Birth:<span class="required">*</span></label><?php e($form->month('mob')); e($form->day('dayborn')); e($form->year('yearborn',date('Y')-18, date('Y')-62)); ?></p> Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-857579 Share on other sites More sharing options...
jcombs_31 Posted June 19, 2009 Share Posted June 19, 2009 Cake is sending the correct data. I'm not sure about how the model automagically handles the arrays when using the month/year helpers. Did you recently change anything with your database? Make sure you always clear the cache if you do. Would it not be better to have 1 field for birthday set as DATE type. If you did that you could just have $form->input('dob']) The form helper will automatically create the drop down selects and handle the data array correctly. Seems to me better practice to use the correct field type for the data. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-859298 Share on other sites More sharing options...
sonoton345 Posted June 19, 2009 Author Share Posted June 19, 2009 Thanks but I want to do is limit the age to between 18 and 62. if I set one input field would I be able to set a minYear and maxYear? Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-859772 Share on other sites More sharing options...
ehutchison Posted June 22, 2009 Share Posted June 22, 2009 check out this page for information on minyear and max year. also, be sure to make sure you validate the information. http://book.cakephp.org/view/189/Automagic-Form-Elements Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-861244 Share on other sites More sharing options...
sonoton345 Posted June 23, 2009 Author Share Posted June 23, 2009 Thanks I have read this page and still not getting the right result. For now I'm just using text fields which is working quite fine but i'll prefer to have the form already populated. Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-862330 Share on other sites More sharing options...
jcombs_31 Posted June 23, 2009 Share Posted June 23, 2009 If you change your database schema to a single date field you can easily set the min/max year with the automagic field types. If you really want to keep these three fields separate, you can try to grab the data from the array and then do your insert. Quote Link to comment https://forums.phpfreaks.com/topic/161704-menu-highlight-to-show-current-page-in-cakephp/#findComment-862344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.