CakePHP links in same page - cakephp

I am trying to build a FAQ page, with table of contents on top and answers below it. I would like to click on a question from the table of contents and link on the same page to the corresponding answer. How can I do this in CakePHP, by using $this->Html->link() method?
Thank you!

use something like this for the link:
$this->Html->link($question_title, $this->here . '#question-' . $question_id);
and then for later down the page put the answers in something like
<div id="question-<?php echo $question_id; ?>"><?php echo $answer_text; ?></div>
obviously the vars will be something like $question['Question']['title'] in cake and the Html->link url could be done with an array like
$this->Html->link($question_title, array('action' => 'faq', '#' => 'question-' . $question_id));
just as long as the url part before the # exactly matches the current url.

Related

how do I use the data in array in joomla list view as a link

I have the following code " which is not quite correct" in a part of a list view in my component. For Joomla 3.4
<td style="text-align:center">
<?php echo JDom::_('html.fly', array(
'dataKey' => 'link',
'dataObject' => $row,
'href' =>array($row->link),
'target' => '_blank'
));?>
I am trying to get the link from the field called link , but every thing I have tried either places the sites url before the link, does nothing or just goes back to the front page of the site. The link field contains a link to another website.
Can someone help me with this code snippet?

How should I handle forms in CakePHP?

I'm studying CakePHP. I read a CakePHP book, and web tutorials, but I still don't get some basic things:
I see people always create a form in View with $form->create. Can I use an HTML form like normal, or must do exactly like people do?
When a form is created in login.ctp with this code:
echo $form->create('User', array('method' => 'POST', 'action' => 'login'));
echo $form->input('email');
echo $form->input('password');
echo $form->input(array('type' => 'submit'));
echo $form->end('Login');
When I click the submit button, will the data be passed to the function login() in the Controller class?
Edited :
I tried this :
<?php
$this->Form->create("Test");
$this->Form->input("stuId",array('class'=>'inputField', 'placeholder'=>'SVxxxxxxxx'));
$this->Form->input("stuName",array('class'=>'inputField', 'name'=>'stuName'));
$this->Form->end();
?>
But it show nothing ? what is the problem :(
But it show nothing ? what is the problem :(
You have to use echo as in your first code snippet:
echo $this->Form->create("Test");
echo ...
You can use HTML for anything you want, but you'd be losing a big advantage of the CakePHP framework. The Cake HTML and form helpers help to future-proof your code. You also get the benefit of Cake's implementation of best practices in web coding. I fully recommend using those helpers.
The form data is passed to $this->request->data.
Yes, the parameters will be passed to login method.
I see $form being used in the form there, it appears you are using older version of cakephp (if $form has been instantiated with $this->Form then you are fine)
The FormHelper does lot of automagic for us and it also provides us means for added security.
I would reckon you to go with The Blog tutorial

How to generate 'a href="javascript:void(0)"' like link in cakephp?

How to generate 'a href="javascript:void(0)"' like link in CakePHP?
I make an application, the content will insert into the editor textarea when user click a list of image. I add a class to these images and write some code in the javascript file. Everything is going well.
But the link of the image is a URL address, but not 'href="javascript:void(0)' like URL. Anyone could tell me how to make it in CakePHP?
Thanks in advance!
<?php
echo $this->Html->link(
'/path/to/image/',
'javascript:void(0)'
);
?>
You can either set a path to the image or use the Html helper to generate the image tag code. The second parameter will set the href.
Don't believe there is any dynamic way, however when you are creating your form element you can set it in the options array 'href' => 'javascript:void(0)'

cakephp problem with frameset

i Have default.ctp.
default.ctp include top.html,center.html,down.html.
And then center.html include left.html, right.html.
I want put my $content_for_layout in the right.html,But I can't do it. if I change right.html to right.php It will tell me
Notice: Undefined variable: content_for_layout in /opt/lampp/htdocs/app/webroot/right.php on line 37. if I change right.html to right.ctp Then it doesn't identify the file.
all the pages I put them in app/webroot/
Could somebody tell me how to do it?
Each of your frames will be loaded through a separate HTTP request and need to pass through the entire Cake framework for their content to be rendered. Just putting $contents_for_layout in some random file will not do much. As such, your frames need to link to Cake URLs:
src="<?php echo $this->Html->url(array('controller' => 'foo', 'action' => 'bar')); ?>"
But really, you shouldn't use framesets in this day and age.

CakePHP passing parameters to action

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

Resources