This is my hyper-link code, everything is working fine but when I click on the last link I can see my view file but after clicking last link I am getting error message when I click rest of the link.My controller name has changed.My main controller name is tutorials. I want to put another controller hyper-link in my my default layout.
Html->link('Home',array('action'=>'index')); ?>
Html->link('Form',array('action'=>'add')); ?>
Html->link('View',array('action'=>'show')); ?>
Html->link('Ajax',array('action'=>'quick')); ?>
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple')); ?>
When you click on the last link you move to another controller, and when you click again on the rest of the links you are going to the Infos controller quick, show, add... methods, and probably they dont exist.
Change the links to this and all links should work through all your site.
Html->link('Home',array('controller' => 'Tutorials', 'action'=>'index'));
Html->link('Form',array('controller' => 'Tutorials', 'action'=>'add'));
Html->link('View',array('controller' => 'Tutorials', 'action'=>'show'));
Html->link('Ajax',array('controller' => 'Tutorials', 'action'=>'quick'));
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple'));
Related
I'm using CakePHP 3.x. I have just installed the source files and the first page that comes up uses the default.ctp layout which calls the home.ctp view. My understanding at the moment is that the view gets placed here in the layout,
<?= $this->fetch('content') ?>
My question is, how come in both the view and the layout some elements and metadata are duplicated. So for instance both call
<?= $this->Html->charset() ?>
<?= $this->Html->meta('icon') ?>
and both duplicate the html structure by using <html>, <head> and <body> tags.
To summarise, if i view the code of the webpage, lots of the structure is duplicated.
Thanks
home.ctp on fresh installed cakephp is just example.
opet that file and see line 22
$this->layout = false;
if (!Configure::read('debug')):
throw new NotFoundException('Please replace src/Template/Pages/home.ctp with your own version.');
endif;
As we see this home.ctp not use layout .ctp, simple clear all code from that file, and add for example:
<h1>This is my new landing page</h1>
save, reload, now your home.ctp use default.ctp layout with meta tags etc..
I am working on CakePHP 2.7. I have to show some static menu on every page. Since, the menu contains lot of sub menus, I want to keep them in a separate file navigation.ctp and show them on default.ctp
I tried extend and elements but none of them give expected result.
Note : This is not dynamic menu and I am not fetching them from database.
Place your navigation.ctp inside app/View/Elements/
Then, inside your default.ctp, include the element as follows:
<?= $this->element('navigation'); ?>
Note that if you need any variables within the element, you may need to pass them through inside an array as a second parameter, such as:
<?= $this->element('navigation', array(
"varible_name" => "variable_value"
)); ?>
I am trying to override the front page node, however after following the guide from the official site, it's not working.
Guide: https://www.drupal.org/node/1585528
I have taken node.tpl.php and renamed it to node--front.tpl.php and made changes to the layout, saved and cleared cache. The changes are not being displayed.
Now if I edit node.tpl.php directly it shows the changes, anyone know what I am doing wrong to override specific node templates?
EDIT:
I want to move the title below the image being displayed in the front page.
See below: Moving the title block under the content block, moves the title down as I want it to do, however how do I specify this for just the front page and not all nodes? (renaming node.tpl.php to node--front.tpl.php does not work as mentioned above)
In node.tpl.php: (title block)
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>>
<?php print $title; ?>
</h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
(content block)
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
To override the node template for particular node, you need to override the default node.tpl.php. For this copy the existing node.tpl.php file to node--{node_id}.tpl.php.
If you want to override the page template only for front page then you can create page--front.tpl.php file and copy the page.tpl.php file and then modify it as per your requirement.
Still you have issues, then use hook_preprocess_page() in template.php and use dpm() function to find the theme_suggestions that will give the sequence of execution of templates file.
you can use node-{nodeid}.tpl.php
It may help you.
Source: https://drupal.stackexchange.com/questions/39710/how-do-i-define-a-template-file-for-a-specific-node-id
Thanks
Samit K
samitkhulve.com
I'm trying to set a variable in a reveal modal with CakePHP.
The reveal modal i'm using is with Zurb Foundation
I have to generate a code and display it.
I have a HomeController with a generatecode() function.
In my Home.ctp I have a div with reveal modal (cf. Basic section here)
I have also a link button generate with that code :
echo $this->Html->Link('Unlock Link', array('action'=>'unlockpwd'), array('class' => 'button small', 'data-reveal-id' => 'modal_unlockpwd'));
Here is my action code :
function unlockpwd() {
$this->set('code', $this->Function->generatePwdLock());
$this->redirect($this->referer());
}
And in my Home.ctp, i just display $code in the reveal modal but i get an undefined variable error.
I think it's because i display the modal before i set $code.
How can I solve this problem ? I tried the setFlash, it works but the reveal modal seems better for the user.
Thanks for your help :)
You set 'code' as a variable and redirect away from the page so the variable is lost. Solution would be to do:
function unlockpwd() {
$this->Session->write('Code', $this->Function->generatePwdLock());
$this->redirect($this->referer());
}
where you want to see it:
echo $this->Session->read('Code');
$this->Session->delete('Code'); //if you want to show only once
Hi im kinda new in cakephp and having a lot of trouble adjusting.. Here's my biggest problem ..
Im trying to pass a parameter to an action, it does load, but when my script goes from the controller to the view, and goes back to the controller again, its gone.
CONTROLLER CODE
function add($mac = 0)
{
if(isset($this->params['form']['medico']))
{
$temp= $this->Person->find('first', array('conditions' => array('smartphones_MAC' => $mac)));
$id= $temp['Person']['id'];
$this->Union->set('events_id', $id+1);
$this->Union->set('people_id', $id);
$this->Union->save();
}
VIEW CODE (This is a menu, i only have one button right now)
<fieldset>
<legend>SELECCIONE SU ALERTA</legend>
<?php
echo $form->create('Event');
echo $form->submit('EMERGENCIA MEDICA',array('name'=>'medico'));
echo $form->end();
?>
</fieldset>
When you create the form you don't include the additional url parameters or the fields as inputs. Without either of these the parameters will vanish as they are not part of the new request. You can append additional parameters to the form submission url with
$form->create('Event', array(
'url' => array('something', 'somethingelse')
));
This will create a form that points at /events/add/something/somethingelse.
I'm no big fan of using some helpers (like $html) or some methods (like $form's create() and end()). I kinda didn't get your problem, but I think it might be that you have to make a POST request to the same url you are actually into.
<form method="GET" action="<?=$this->here ?>">
Maybe you should give a further explanation of what you are trying to achieve.
You might want to try using named parameters.
I asked a similar question which you might find helpful:
cakephp adding record with some parameters fixed