I am having a problem using $html->link helper in my view. Consider this snippet...
/views/nodes/packages.ctp
<li><?php echo $html->link( "Package 1", array( "packages", "package1" ) )?></li>
Now when I click on the link, the address in address bar appears like
http://www.server.com/nodes/packages/packages/package1
Why is this happening? I haven't changed anything in my default routing configuration file.
Regards
Vikram
Let me answer this myself...
<li><?php echo $html->link( "Package 1", array( "controller" => "packages", "action" => "package1" ) )?></li>
I forgot to write the keys "controller" and "action". Silly me!
Regards
Related
Have a form.
$this->Form->create(array('controller'=>'bookings','action'=>'book'));
But for some reason, instead of BookingsController it is searching RoomsController for
the specified action.
Please help. Using Cakephp 2.3
TLDR:
echo $this->Form->create(
'Booking', //notice this - the first item
array(
'url' => array(
'controller'=>'bookings',
'action'=>'book'
)
)
);
Explanation:
Probably a good idea to look at the documentation instead of just guessing at it's syntax:
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
:)
Hi all creating a link that when you click it, it opens a new window. I was wondering if it's possible to restrict the size of the window opening?
this is the code I have for the link that opens the window
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array('target'=>'_blank', 'escape'=>false)); ?>
You can do this, but only with Javascript.
Raw code would be something like:
Text Link
The only parameters you really need are width and height, but you might find the others useful too. If not, just delete them. If the user doesn't have javascript, it'll just open the link normally.
To do it with html helper, pass your javascript through to the onClick array key:
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array(
'target'=>'_blank',
'escape'=>false,
'onClick'=>"window.open('/pages/home', 'windowname','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=290'); return false;"
)); ?>
PS - you can read up on the window.open method here: http://www.w3schools.com/jsref/met_win_open.asp
Seems simple but I can't figure it out. Every link on my website suddenly shows the path behind the link
Example:
Not a member yet? Please register(/users/register) to add your pitch.
I can't select the path with Firebug to trace where it is coming from. Anyone has an idea? Thanks
UPDATE:
The PHP code for this link is:
echo $html->link('register', array('controller' => 'Users', 'action'=>'register'));
I use the BluePrint CSS Framework
Your problem isn't the style rule. Your problem is that you are linking a print only stylesheet from blueprint as a normal (screen, projection) stylesheet.
You need to make sure your css link has 'media' = 'print' as one of it's attributes.
IE
<?php
....
echo $this->Html->css( array(
join( DS, array( 'blueprint', 'print' )),
'stylesheet',
array( 'media' => 'print' )
);
...
?>
Somewhere in the head section of your layout.
try this...
$this->Html->link(__('register', true), array('controller' => 'Users', 'action' => 'register'));
cakePHP v. 1.3
I am very new in cake php, i want to know how to create form in cake php,please describe,when we go to create a form then what i have to do,like create model and controller everything
In the view file, something like this would work:
<?php
echo $this->Form->create();
echo $this->Form->input('firstname', array('label' => 'Enter your first name:'));
echo $this->Form->input('email', array('label' => 'Enter your email address:'));
echo $this->Form->input('password', array('label' => 'Enter your password:'));
echo $this->Form->end('Save');
?>
In your controller:
if($this->request->is('post')){
$this->User->save( $this->request->data );
}
You can apply some sort of validation in your model, look in the documentation for that.
Best option to learn about cakephp is it's own doc book
But I'm providing you some basic code to create form :
$this->Form->create('ModelName');
$this->Form->input('ModelName.fieldname', array('type'=>'text', 'label'=>'Modified-Name'));
$this->Form->end(__('Submit'));
Here array('type'=>'text'...): type shows which type of input field you want.
(...'label'=>'Modified-Name'): By default it shows field text as fieldname but by using 'label' you can modify your field text.
$this->form->create('controlpage',
array(
'action'=>'controll',
'class'=>'class',
'enctype' => 'multipart/form-data',
'onsubmit'=>'return valid()'
));
Block quote
Create form in html save it as ctp
Block quote
And call it in view. enter code hereUse cake php book to read further.
How can I use $html->link from within an element?
Thanks,
Tee
In both 1.2 and 1.3,this should work:
echo $html->link('linkname',array('controller'=>'somecontroller','action'=>'someaction/somearguments'));
Update
The html helper has changed a little in version 2.x.An example from the cook book
echo $this->Html->link('Enter', '/pages/home', array('class' => 'button', 'target' => '_blank'));
The new version of Cakephp has easier ways to work with html->links, definitely you can convert links into buttons.
If you want using bootstrap or some css however for normal links you can use:
<?= $this->Html->link ('Sometexthere', ['controller' =>'myController', 'action' =>'myAction']); ?>