adding css to a image in cake php - cakephp

I am moving my website to use cake php and before i would just have to include an image like this in my project print("<img class='custom' alt='' src='$dish_image' />"); as you can see I included the css class to be used. But now with cake php I am not sure how to achieve as my image tag looks like this
echo $this->Html->image($dishes['Dish'][0]['dish_image'], array("alt" => ""));
So i am not sure where to apply that custom css to it... The css is in a separate css file.
Any help would be appreciated/

This should do it:
<?php echo $this->Html->image($dishes['Dish'][0]['dish_image'], array(
"class" => "custom",
"alt" => ""
)); ?>
Good luck!

Related

Using Meta Description in the right place CakePHP 3

I am trying to use meta tags and description in cakephp 3. It is working so far, but I am facing the problem that I canĀ“t put it in the of my page, because my .ctp files are rendered in my default.ctp
So for example I have my menu, footer etc. in my default.ctp and my page for the faq is in the faq.ctp How can I push those
<?php
echo $this->Html->meta('description','enter any meta description here');
?>
metadescription in the head tag? Do I need a template language like smarty and use blocks?
In layout:
<?php
echo $this->Html->meta('description',$description);
?
in your faq.ctp or faq() method:
<?php
$this->set('description','enter any meta description here');
?
add this in your ctp file (there is NO echo )
<?php $this->Html->meta('description', 'some text here', ['block' => true]);?>
and this line into your layout
<?php echo $this->fetch('meta');?>
see also similar question with title: $this->set('title', 'Title Name'); not working in CakePHP 3.x

Best way to style cakephp app

I've got a template X and I want this to become the default style. Meaning I don't want to do this:
echo $this->Form->input('phone',array('class'=>'form-control'));?>
I want to just do this:
echo $this->Form->input('phone');
Do I edit the FormHelper, create a new helper, or do I rewrite the styles in cake's style.css with the those from template X?
The best and cleanest way is to override the FormHelper. So you create a new helper, and then in the respective controllers you can add:
public $helpers = array('Form' => array('className' => 'newFormHelper'));
Look here for more references: http://blog.nlware.com/2012/02/07/cakephp-2-0-how-to-extend-the-formhelper/
You can specify inputDefaults in your create method.
$this->Form->create('Model', array(
'inputDefaults' => array(
'class' => 'form-control'
)
);
There are more options you could use if you wish, it sounds like this is for bootstrap so you might want to checkout BoostCake
https://github.com/slywalker/cakephp-plugin-boost_cake

how to rander .html file using cakephp : CakePHP

I am working on CakePHP and I have a URL http://admin.example.com/Pages .
How can I create http://admin.example.com/Pages.html ? Is there any solution or component to solve this issue?
According to CakeBook , You can define extensions you want to parse in routes
E.g. Write the code below in app/Config/routes.php
Router::parseExtensions('html');
This will allow you to send .html extenstion in routes(url)
Not create a link
E.g:
$this->Html->link('Link title', array(
'controller' => 'pages',
'action' => 'index',
'ext' => 'html'
));
When you click that link you will get url in browser something like this
http://admin.example.com/pages/index.html
Do you really need this? CakePHP is automatically render view files from View folder
You can create (if its PagesController and index methond) index.ctp in app/View/Pages folder and it will be automatically render.
You can use file_get_contents function to read files. Something like this:
// in controller
function index() {
$content = file_get_contents('path/to/file.html');
echo $content;
die();
}

Wordpress php use wp_nav_menu to display all pages in menu

I am currently building a wordpress theme. For the menu, I just want to display all the pages that are created in the order that they are created in (i.e. I don't want users to have to go into the 'menu' section of the site and create their own).
I tried using wp_page_menu and this worked HOWEVER I need to add a walker class to expand the functionality, which you can't do with this function. So I need a way to display all my pages with using wp_nav_menu as my code - is there a way to do this?
Here is my code currently:
<nav id="nav">
<?php wp_nav_menu( array( 'walker' => new Clapton_Nav_Walker ) ); ?>
</nav>
Try this
functions.php this below code register a menu for use
<?php register_nav_menu( 'main_menu', 'Primary Menu' ); ?>
// remove <?php ?> tags if it already there
index.php or wherever you want, below code output the menu
<?php wp_nav_menu( array( 'theme_location' => 'main_menu','walker' => new Clapton_Nav_Walker ) ); ?>
Build menu in WordPress Dashboar -> Appearance -> Menus -> Manage Locations

Cakephp breadcrumb

I am a Cakephp beginner
I am creating breadcrumbs from my website, I am not sure what is the difference between using HTML helper and Breadcrumb helper, Html helper seems easier to use, but it seems like I have to add each crumb to each page manually, please correct me if i am wrong.
When I was trying to use the Html helper, I put
<?php echo $this->Html->getCrumbs(' > ', array( 'text' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index'), 'escape' => false)); ?>
in my index.ctp
then, i put
<?php $this->Html->addCrumb('Add customer', 'Customers/add'); ?>
in add.ctp
the breadcrumb "Customer" appears on the index.ctp, but when i go to the add.ctp page, no breadcrumb is shown.
I tried putting
echo $this->Html->getCrumbs(' > ', 'Home');
in default.ctp, then the "Add customer" appears after the Home crumb
How can I make it so that, on the add.ctp , the breadcrumb shows like this:
Customers > Add customer
You should take a better look at the documentation in the cookbook, usually it's all there.
Steps are:
Create a place for cakePHP to display the breadcrubs in your layout template, not index.ctp using something like echo $this->Html->getCrumbs(' > ', 'Home');. You should find your default layout in View/Layout/default.ctp.
Add a trail in each page with something like $this->Html->addCrumb('Add customer', 'Customers/add'); for View/Customers/add.ctp
This is all done by the HTML helper, there isn't any different (official) breadcrumb helper.

Resources