I have problem with addCrumb() method it doesn't work for me when I use getCrumbs() everything is fine but with addCrumb() method I don't get anything shown in my view I load HTML helper in my AppView and I did everything by CakePHP book but I still don't get breadcrumb trails this is my code sample:
<?php echo $this->Html->getCrumbs('>', [
'text'=>$this->Html->image('home.png',['alt'=>'Home','height'=>50,'width'=>50]),
'url'=>['controller'=>'Pages','action'=>'display','home'],
'escape'=>false
]);
$this->Html->addCrumb('Users','/users');
$this->Html->addCrumb('Add User',['controller'=>'Users','action'=>'add']); ?>
?>
I also got confused looking at cake documentation at first. But later I figured it out.
The order of your code is wrong. First you have to do
$this->Html->addCrumb('Users','/users');
$this->Html->addCrumb('Add User',['controller'=>'Users','action'=>'add
Then the getCrumbs,
echo $this->Html->getCrumbs('>', [
'text'=>$this->Html->image('home.png',['alt'=>'Home','height'=>50,'width'=>50]),
'url'=>['controller'=>'Pages','action'=>'display','home'],
'escape'=>false
]);
Related
I'm using PlatesPHP on a very basic level with static data rather than extracting it from db.
In my controller I have:
<?php
require 'vendor/autoload.pkp';
echo $templates->render('index', [
'project_1_checklist_point_1_help' => 'Google',
]);
and then in the index.php the following
<p><?=$this->e($project_1_checklist_point_1_help)?></p>
and in the template.php standard html skeleton.
It shows up as
Google
rather than a link, which I want.
Google
I've tried htmlentity() and htmlspecialchars(), but they are not what I was looking for at all.
Any ideas?
Cheers!
If you want the un-escaped string, just echo the variable without the method $this->e():
<p><?= $project_1_checklist_point_1_help ?></p>
The method $this->e() (short for $this->escape()) is equal to htmlspecialchars(), which html-encodes the string.
You can read more in depth about it the manual: http://platesphp.com/templates/escaping/
Long time reader, first time poster :)
I'm just embarking on my first Cake app so hopefully you guys can help me on my way.
First question is about extending/including views. I realise the way the layouts/view work is to prevent code having to be repeated, but I can't get my head around how to set up what I want to do without some repetition.
My page layout consists, apart from header and footer, a left nav bar which I want Controllers to add themselves to if appropriate, and a top nav bar which will be populated by appropriate pages within the current controller.
I tried creating a view block from within the controller but it didn't work, I'm a bit stumped.
Here's what I have:
My default layout includes the sidebar, currently just hardcoded, and the content:
Layout default.ctp
<!DOCTYPE html>
<html>
<head>.....</head>
<body>
...
<div id='leftnav'>
This is where I want my left nav
I want controllers to be able to add themselves
here.
</div>
<?php echo $this->fetch('content'); ?>
</body>
</html>
Then my /Customer/index view:
View index.ctp
<?php $this->extend('common'); ?>
<h1>Customers</h1>
.... do stuff with customers .....
Which extends my /Customer/common view to bring in the top nav bar, each view has to include this extend line, it would be nice not to have to if there's a different way of doing this.
At the moment, the links are just fixed but I'd like the controller to be able to create these options.
View common.ctp
<?php
echo $this->Html->Link('index', "index")." ";
echo $this->Html->Link('find', 'find')." ";
echo $this->Html->Link('add', 'add')." ";
echo $this->Html->Link('details', 'details');
echo $this->Session->flash();
echo $this->fetch('content');
?>
Appreciate your help cheers! :D
I think you should just be able to put those links in your layout file. But you may have to re-write them as "$this->Html->link("Index",array("controller => $controller","action" => "index");" etc.
To get the current controller within the layout file you can say "$controller = $this->params['controller']".
right, after searching around I think I found a good way of doing at least one of these things.
For the top nav, where the links will be populated by the controller, I'll pass an array from the controller to view. Then, instead of having an ->extend in every view I'll create an element to turn the array into a nav bar, and ->fetch this in the layout.
This leads me onto my next question....
How much code is ok in a CakePHP Layout?
Hi you can use Cake PHP HTML Helper
https://book.cakephp.org/3/en/views/helpers/html.html#creating-links
echo $this->Html->link('Users List', ['controller' => 'Users','action' => 'index']);
Output will be look like this:
Users List
I've been given a website to maintain. The website is using PRADO framework and I had to do some minor changes. There were no problems with the HTML and CSS changes, but now I have to pass some data from a page to a view.
I've tried using:
$this->HomeCalendar2->DataSource = $result['data'];
$this->HomeCalendar2->dataBind();
but it says Component property 'Home.HomeCalendar2' is not defined.
Above my code there is the following code:
$this->HomeCalendar->DataSource = $result;
$this->HomeCalendar->dataBind();
and it works perfectly fine and I can't see where is the definition of HomeCalendar.
Any help will be appreciated.
P.S: I've never worked with PRADO before.
This question is quite old now, hope you already solved it.
Using DataSource means that there must be in your template (.page or .tpl) a TDataBoundControl component like the folowwing (using TRepeater for example)
<com:TRepeater ID="HomeCalendar">
<!--- [ properties like ItemTemplate here and it contents ] --->
</com:TRepeater>
Subclasses of TDataBoundControl are for component needing to loop results, (sorts of for or foreach somehow).
If you juste need to pass a signle result to the view you can use a component like TPanel/TActivePanel, TLiteral, etc. or simply use the expression tag.
Examples :
Expression tag :
Php :
<?php
$this->myvalue = 'Hello World!';
Template :
<h1><%= $this->myvalue %></h1>
Or another solution:
Template :
<com:TLiteral ID="MyLiteral" />
PHP :
<?php
$this->MyLiteral->getControls()->add('<h1>Hello world !</h1>');
I've tried doing the following in my 404 error page to create a back link the referring page so that I don't have to rely on javascript.
<?php $this->set('refer', $this->referer()); ?>
<p><?php echo 'Back to previous page'; ?></p>
However it doesn't work... Any ideas why? This code is done in /Errors/error404.ctp
Use the request object :)
$this->request->referer();
In CakePHP3 you can use:
<li><?= $this->Html->link(__('Back'), $this->request->referer()) ?></li>
It should be fine.
Try adding this to the beforeRender method of your app controller:
beforeRender() {
$this->set('refer',$this->referer);
}
It should be available to all views then.
What about using just $_SERVER['HTTP_REFERER'] instead? I know this is not the Cakey way to do it but it seems like it would work in your case.
$this->request->referer() works in .ctp file for Cakephp version 2.8.0
<?php echo $this->Html->link(__d('user', 'Login', true), $this->request->referer(), array('class' => 'login_text')); ?>
I'm following CodeIgniter's tutorial "Create a blog in 20 minutes" and I am having trouble getting the helper, anchor and Scaffolding functions to work.
I can't seem to create links on my HTML page using the helper and anchor functions.
I put
$this->load->helper('url');
$this->load->helper('form');
in the constructor under
parent::Controller();
and
<p><?php echo anchor('blog/comments','Comments'); ?></p>
within the foreach loop as specified in the tutorial. But Im not getting the links to appear.
When I viewed the source as instructed in the video, this line was missing (but it was in in the video):
<form method= "post" action = "http://www.example.com/CodeIgniter/index.php/blog/comment_insert">
Secondly, I keep getting a 404 Page Not Found error whenever I try to access CodeIgniter's Scaffolding page in my browser, like so:
localhost/codeignitor/index.php/blog/scaffolding/mysecretword
I can access
localhost/codeignitor/index.php/blog
just fine. I followed CodeIgnitor's instructions in their "Create a blog in 20 minutes" by storing my database settings in the database.php file; and automatically connecting to the database by inserting "database" in the core array of the autoload.php; and I've added both
parent::Controller(); and $this->load->scaffolding('myTableName') to blog's constructor. It still gives me this 404.
Any assistance will be appreciated. Thanks in advance?
Scaffolding is deprecated, but it hasn't been removed until 2.0, and still works in 1.7.2.
You have /scaffolding/ in the URL which isn't necessary, you just use your scaffolding trigger.
I'm not sure why your helpers aren't working, your syntax looks good, unless you don't have any data in your foreach loop. the <form...> line comes from calling <?php echo form_open('form_controller_or_whatever'); ?>
localhost/codeignitor/index.php/blog/mysecretword
is just enough ....
check out this site:http://www.schobbing.de/user_guide/general/scaffolding.html you'll get a clear understanding ....