Cakephp echo username into page title - cakephp

I am currently learning Cakephp and have made a profile page of which displays the username on it. You can only access this page when logged in so when you are on this page, I wish to display the username of the user in the HTML page title. This is also because your profile page is visible to other users.
At the moment to get the page headers I have used.
<title><?php echo $this->fetch('title'); ?> | Site Name</title>
<? $this->assign('title', 'Profile')?>
And to display the username on the page currently I have:
<?php echo $user['User']['user_name']; ?>
I have attempted to combine these two into something like shown below but clearly that's not working. Any ideas?
<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>
Thanks!

Mistake in the concatenation, change this in your .ctp
<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>
to this
<? $this->assign('title', $user['User']['user_name'])?>
Later on add this in your layout
<title><?php echo $this->fetch('title'); ?> | Site Name</title>
This will work :)

Related

cakePHP 3.3 internationalization

How can I set multiple language in case text is in array?
I know that if I use this
<?= __('username')?>
and in directory /src/Locale/de_DE/default.po
I have written following
msgid "username"
msgstr "benutzer"
It's gonna change username to benutzer if I set language to de_DE (german)
But what to do if I have this
<?= $this->Form->input('password',['label' =>'Password']); ?>
and I would like to change label Password
Simple:
$this->Form->input('password', ['label' => __('Password')]);
The __() function simply returns the translated string (more info). In your example you used
<?= ... ?>
which is equivalent to
<?php echo ... ?>

Meta noindex in post and page untranslated (unavailable) with Yoast

Is possible enter in the of posts and pages untranslated a meta robots noindex?
Of course, versions already translated, must instead stay indexable ...
I have Yoast SEO plugin compatible but I can not change meta robots per single language.
Just put this in the header of your theme. Language plugin that I use is qtranslate:
<!--Begin add noindex and nofolllow when not translated post in current lang-->
<?php if ( have_posts() && is_single() ) : while ( have_posts() ) : the_post();
$lang_current =qtranxf_getLanguage();
$id = get_the_id();
$exist_translate = qtranxf_isAvailableIn($id, $lang_current);
if (! ($exist_translate) ) : ?>
<meta name=“robots” content=“noindex,nofollow”>
<?php endif;?>
<?php endwhile;?>
<?php endif; ?>
<!--End add noindex and nofolllow when not translate post in current language-->

How to add two calendars in a page - Joomla

I am new to joomla, want to implement two calendars in a page ...
From :
<?php
echo JHTML::calendar('sch_from', 'sch_from', '%Y-%m-%d');
?>
To :
<?php
echo JHTML::calendar('sch_to', 'sch_to', '%Y-%m-%d');
?>
But first calendar only working... is there any issue in code?
syntax is:
JHtml::calendar($value,'nameOfField','idOfField', '%Y-%m-%d');
located at libraries/cms/html/html.php
try
From :
<?php
echo JHTML::calendar('','sch_from', 'sch_from', '%Y-%m-%d');
?>
To :
<?php
echo JHTML::calendar('','sch_to', 'sch_to', '%Y-%m-%d');
?>

Why doesn't my CakePHP flash message appear?

Background: I'm new to CakePHP. I have a small test site (mostly composted of static views and a contact form at the moment) to play with while I learn. Everything worked fine on localhost (Apache on Ubuntu) so I deployed it to a shared hosting account (provided by Lunarpages). I moved the /cake folder out of the normal directory structure (so I could use it for multiple apps) and I reconfigured my webroot's index.php paths accordingly.
Problems:
setFlash messages do not get displayed. Even making a simple view that does nothing other than $this->Session->setFlash('message');. I don't get any error message, the flash just doesn't get displayed
Redirects don't work. For instance, after the contact form is completed I want to $this->redirect( array( 'action' => 'success' ), null, true); but the server throws an error:
Warning (2): Cannot modify header information - headers already sent by (output started at /routetoapp/config/routes.php:40) [CORE/cake/libs/controller/controller.php, line 742]
Everything else seems to work just as it did on localhost - URL rewriting, component loading, model validation. I don't know if my problems are related or separate issues
Troubleshooting so far:
I've tried both 'cake' and 'php' for Configure::write('Session.save', 'val'); but neither made a difference.
My app/tmp folder is writeable.
My layout template has the correct code for displaying flash messages. (The exact same M, V, C, and Layout objects display the expected flash on localhost)
I assume I'm missing something simple, but I'm new to this framework so I'm not sure where else to look.
See Matt Huggins answer for your flash problem. That's correct
As for your redirect issue,
you might have an extra space or something in your routes.php file. Make sure there are no spaces before the starting <?php tag and remove the closing ?>
$this->Session->setFlash(...) is used to SET the flash message from within the controller. When you're in the view, you should be rendering the flash message like this:
<?php $session->flash(); ?>
You can also make your flash message more elaborate if you need with something like this:
<?php if ($session->check('Message.flash')): ?>
<div class="message">
<?php $session->flash(); ?>
</div>
<?php endif; ?>
That was right but there also have echo add before $session->flash();
so, it should be like:
<?php if ($session->check('Message.flash')): ?>
<div class="message">
<?php echo $session->flash(); ?>
</div> <?php endif; ?>
this worked for me!

cakephp + cache + formhelper inside <cake:nocache></cake:nocache> = error

in all my views i have a login/register (cake)form.
my question:
can i use the file cache engine with <cake:nocache>form</ cake:nocache>
1.) open url "www.domain.com/home"
2.) cachefile generated
3.) look perfect
4.) refresh (f5)
5.) error (when debug=1):
Parse error: parse error in C:\xampp\htdocs\cake_1.2.3.8166\app\tmp\cache\view \cake_1_2_3_8166_home.php on line 752
cachefile -> line 752 -> </html>
cakephp: 1.2.3.8166
example:
<cake:nocache>
<?
$user = $session->read("user");
if(!$user){ //$user true or false
echo "login:";
echo $form->create('AdminUser', array('action' =>'login_load'));
echo $form->input('email',array('label'=>false));
echo $form->input('password',array('label'=>false));
echo $form->submit('Login', array('id'=>'login'));
echo $form->end();
}else{
echo "hello user!";
}?>
</cake:nocache>
it's a cakephp bug. cake google groups
The dev state at https://trac.cakephp.org/ticket/6034 CakePHP does not support using the form helper from within tags at this time.

Resources