cakephp 1.3 favicon - cakephp

I am using cake 1.3 and i had tried to implement favicon..But some strang error happens and sometime its showing favicon but for sometimes its not showing it.Pronlem is cakephp img folder path is changing>How can i escape from this problem.
i have used below code in my default.ctp
<?php echo $this->Html->meta('favicon.ico','../../app/webroot/img/favicon.ico',array('type' => 'icon'));?>
Favicon shows for following url.
http://localhost/finalportal/index.php/events/eventlist
Favicon not showing for followin url
http://localhost/finalportal/index.php/productsServices
I had tried this also.
<?php echo $this->Html->meta('favicon.ico',/favicon.ico',array('type' => 'icon'));?>
in this case favicon path is not correct
What i am doing wrong

meta('favicon.ico',$this->webroot.'img/favicon.ico',array('type' => 'icon'));
It works perfectly, just create favicon.ico image in img folder.thats it.

Don't use relative paths in the HtmlHelper, Cake prepends the correct path for you.
I haven't use the meta function, so I'm not sure if it respects the Cake directory conventions (e.g. images are in img, JavaScripts in js), but this should work:
<?php echo $this->Html->meta('favicon.ico','/img/favicon.ico',array('type' => 'icon'));?>

use following code to get right path.
<?php echo $this->Html->meta('favicon.ico',$this->webroot.'img/favicon.ico',array('type' => 'icon')); ?>

The problem in the first version is that you're using relative paths so it will always end up pointing to the wrong place, depending on how many parameters the URL has. ../../app/webroot means "two levels down, then to directory app/webroot". Two levels down from http://localhost/finalportal/index.php/events/eventlist is http://localhost/finalportal/index.php/, but two levels down from http://localhost/finalportal/index.php/productsServices is http://localhost/finalportal/, so you end up in the wrong place.
The reason why the second method (which is syntactically correct) doesn't work is probably because you have the server set up wrong. Apache's DocumentRoot should point at the app/webroot directory or the .htaccess file in the root directory should redirect requests to app/webroot.

Related

cakephp Managing Plugin Views how to determine paths

I have a plugin installed that has its own layout overrides for different controllers. However I'm having trouble understanding the mechanism for modifying the paths.
In the plug-in controller if I tell it to use my layout
$this->layout = 'default_dashboard';
Which is in app/Views/Layout and references an image in app/webroot/default_images.
All the relative links work fine to default_images when I do this, but would like to use some of the Plugin template overides for other actions.
However if I modify the default.cpt file to include some of the images, like say a logo that is used in default_dashboard.ctp. It is unable to map to the same image location.
For example in default.ctp:
echo $this->Html->image('default_images/logo.png',array('alt' =>
'Logo','width'=>'284','height'=>'82'));
produces a path to /img/default_images/logo.png. The Plugin is configured to use the /img location, whereas I want to direct to /default_images in this case. I could make this ../default_images/logo.png, but this isn't very clean.
In addition I have js and css which is having a similar problem. Can someone please explain the mechanism for using a site-wide default.ctp so that it works with inherited plugin templates?
From hard coding the links into the template not using the Html Helper, I see that the browser's relative path is confused because of the routing. For example the first one works with the root specified, the second doesn't.
<img src="/default_images/logo.png" alt="works" width='284' height='82'>
<img src="default_images/logo.png" alt="lost" width='284' height='82'>
What's the best way to make sure that the Plugin layouts and non-plugin layouts can all find the correct path to /default_images ?
Following are the steps that you can follow to resolve relative path problem:
Create a file abc_constants.php in app\Config folder.
Include the file in app\Config\bootstrap.php
require_once(abc_constants.php);
abc_constants.php should contain:
define('HTTP_HOST', "http://" . $_SERVER['HTTP_HOST'].'/');
define('SITE_URL', HTTP_HOST.'your_app_name/');
define('IMAGE_HTTP_PATH', SITE_URL.'app/webroot/default_images/');
Use these constants in your view file accordingly.
<?php echo $this->Html->image(IMAGE_HTTP_PATH.'logo.png',array('alt' => 'Logo','width'=>'284','height'=>'82'));
It looks a bit lengthy process at first time, but once implemented, you can use these constants in Ajax calls in view files, controller's code etc.

HTMLHelper link() added unintended path

I believe this is very simple question. Maybe that's why I can't find it on Google.
When I do this inside View/Product/view.ctp
echo $this->Html->link('Download PDF', 'app/files/product/1/manual.pdf');
The resulting URL is like this:
app/products/app/files/product/1/manual.pdf
It automatically added app/products since this is inside Product's view.
How to nullify that automatic addition?
Thanks
You're specifying a relative url, causing your browser to append the url to the current url.
echo $this->Html->link('Download PDF', '/app/files/product/1/manual.pdf');
(note the leading slash /)
Should result in a link to http://example.com/app/files/product/1/manual.pdf

cakephp element error (Element Not Found)

i've just started using cake 2.2 (usually i use 1.3) and i have a problem with view elements. i need to create an element for my application, being used in homepage and some other places.
i think i've done all the things right:
i have an action in the controller (ads/latest)
i've created the element in app/View/Elements/latest.ctp
i call it in the home.ctp like this: <?php echo $this->element('latest'); ?>
but it gives me this error "Element Not Found: Elements/latest.ctp"
A few things could cause that:
there's a difference between the filename and the element() call
the element call should NOT include ".ctp"
the element file has an incorrect extension (should be .ctp)
file permissions on the element are incorrect and don't allow access
the path to your element is incorrect (ie it's in a folder, but you're not specifying that in the call)
If you pass all those tests, you should be good to go and not get any errors.

how to use new image folder in cakephp

I have created a folder in app/webroot/. for image placing. eralier by default img folder cantain image. which I have used some thing like this:
<?php
echo $html->image('foldopen.png',array('width'=>14,'height'=>'10','alt'=>'open'));
?>
now I have created new image folder insted of img folder. how to use this?
use a slash at the beginning of the path. For example
echo $html->image('/images/foldopen.png');
Using the slash at the start is relative to the app/webroot directory
Just create your folder in webroot folder (test) and use like this:
echo $this->Html->image('/test/image.jpg');
I created one images folder in webroot dir. I used
$this->Html->image('../images/profile_image.jpg');
in my cakephp2.1 application. this worked for me.
or you can just change the App.imageBaseUrl in app/Config/core.php
If you want to keep your $html->image() statements short and modify the default image route you could always override the default behavior of image() by altering the config/tags.php file.
more info on changing the tag output

Linking to a file (e.g. PDF) within a CakePHP view

I'd like to link to some PDFs in one of my controller views. What's the best practice for accomplishing this? The CakePHP webroot folder contains a ./files/ subfolder, I am confounded by trying to link to it without using "magic" pathnames in my href (e.g. "/path/to/my/webroot/files/myfile.pdf").
What are my options?
EDIT: I didn't adequately describe my question. I was attempting to link to files in /app/webroot/files/ in a platform-agnostic (ie. no mod_rewrite) way.
I've since worked around this issue by storing such files outside the CakePHP directory structure.
$html->link('Pdf', '/files/myfile.pdf');
This is somewhat tangential, but for access to such a location in Models and other places you can simply do this:
$file = WWW_ROOT . DS . 'files' . DS;
This tactic might be helpful to someone accessing files for static data loading, such as XML or JSON.
This is not recommended for public consumption or public linking.
I can confirm that this is an issue when mod_rewrite is not being used.
<?php echo $html->link('pdf', '/files/test.pdf'); ?>
outputs
pdf
it should output
pdf
This should work
<?php echo $html->link('pdf', $this->webroot('files'.DS.'test.pdf'); ?>
I'm not sure I understand the question correctly, but here goes. Basically any file you put in the webroot folder will be accessible on the webserver, so if you put the file in webroot/files/file.pdf you would simply link to /files/file.pdf.
If that doesn't work, please clarify your question...
or..
Link Text
:)
or...
Link Text
Descargar Archivo

Resources