Reputation: 2474
In my default layout I have 3 links, i need to pass values to these links from search action colleges controller.
My default layout links
<li class="single-link">
<a href=<?php echo ROOTPATH.'Inventions';?>>Invention</a> </li>
<li class="single-link"><!-- Using class="single-link" for links with no dropdown -->
<a href=<?php echo ROOTPATH.'technology';?>>Technology</a> </li>
<li class="single-link"><!-- Using class="single-link" for links with no dropdown -->
<a href=<?php echo ROOTPATH.'enterper';?>>Enters</a> </li>
<li class="single-link">
My search view form
<div class="searchbox" align="center">
<form id="form1" name="form1" method="post" action="/inno/colleges/search" >
<label><span class="style14">Enter College Name</span>
<span class="style14">
<input type="text" id="tags" name="data[College][name]" size="70"/>
</span><span class="style12"> </span><span class="style10"> </span> </label>
<label>
<input type="submit" name="Submit" value="Explore"/>
</label>
</form>
</div>
In all 3 above href i need to add one more parameter which I set from seacrh action? can we do this ?
Upvotes: 0
Views: 1629
Reputation: 122
Correct way to get Values from Action to a View (Layouts too).
Is to set them in the Action like that :
In Seach-Action:
$this->set("testing","testing_string");
at the layout (default.ctp)
<?=$testing?>
You will may need them initialized otherwise if you enter the Application
you will get an undefined Variable Error.
Upvotes: 0
Reputation: 12611
Try putting
$this->set("variable_name","contents");
in the AppController's beforeFilter()
method (if you haven't got that, just create public function beforeFilter() { ... }
)
Upvotes: 0
Reputation: 848
You can pass the values in the same way as you pass the values in view.
In Action
$this->set('yourkey', 'your-value');
And in layout you can get 'your-value' in $yourkey variable
Upvotes: 1