Jump to content

Recommended Posts

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?

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.

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.

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

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.

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

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

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.

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>

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.

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.