Set title Cakephp 2.x - title

I am trying to change the title of a page.
The default.ctp view has the following code:
<title>
<?php echo $this->fetch('title'); ?>
- Welcome
</title>
I'm trying to use the following code in the controller of the page:
$title = 'Overview';
$this->set('title');
But unfortunately I do not see see 'Overview - Welcome', but only the name of the function of the controller followed by ' - Welcome'.
Can anyone help me to find the problem why it is not working?

Don't know if $this->set('title') will work
I usually use the 'compact' function to set the variables as they're named.
Like this: $this->set(compact('title')); or just simply this $this->set('title', $title);

You can define what $this->fetch('title') returns using View::assign() function that sets block's value this way:
$this->assign('title', $title);
See more in the documentation about view blocks.

I think instead of:
$this->set('title');
you must use:
$this->set('title', $title);

Related

zend framework 2 change head title

I'm trying to change headtitle on ZF2 but it always say "ZF2 Skeleton Application" when i paste it on FB
How can I change it?
I tried few things and cant make it work
I event tried raw HTML inside head tag to put it and it doesn't work, BUT on my other pages this works but don't know why
echo $this->headTitle('you are on '.$news.' ');
inside PHP ofc
If you want to set head title, Do not use 'echo' in front, just use:
$this->headTitle('you are on ...');
...in your view php file.
If you want to change the head title from inside a controller method use:
$this->getServiceLocator()->get('ViewHelperManager')->get('HeadTitle')->set('my title')
To my understanding you want to change the head title of the main (front page).
You can put the following in your layout.phtml page.
<?php echo $this->headTitle('you are on'. $this->translate($news))->setSeparator(' - ')->setAutoEscape(false); ?>

Link a prettyphoto including an iframe from a parent page

I try to write a link from a first page that will open a second page that includes prettyphoto and automaticaly open the prettyphoto plugin including a third page. Doing that, I've got to transmit a variable from the first link and retrieve it in the third.
Is it possible ?
Yes, it is: If the first an the third website were running on the same server you wil be able to use HTML5 Web Storage or Cookies. Here's an example (HTML5 Webstorage):
// Save...
localStorage.setItem('item', myVariable);
// Open...
var myVariable = localStorage.getItem('item');
I have found the following issue
I added a variable into the link of the first page
mypage.php?my_variable=<? echo $id; ?>
and on the second page, test the presence of this variable to implante an automatic launch of prettyphoto into the jQuery function init :
<?PHP
if(isset($_GET['my_variable'])) {
$id = $_GET['my_variable'];
?>
$.prettyPhoto.open('third_page.php?id=<?PHP echo $id; ?>&ie=UTF-8&oe=UTF-8& q=prettyphoto&iframe=true&width=100%&height=100%');
<?PHP
}
?>
I'm now looking for a full screen prettyphoto auto opening, but that's another problem, the main problem is solved for me.

Dojo attach point / byId returns undefined

I made a template and there is a <select dojotype="dijit.form.ComboBox" dojoAttachPoint="selectPageNumber" id="selectPageNumber">tag with id and dojoAttachPoint be "selectPageNumber". I want to populate it with options upon create so I add some code to the postCreate function:
var select = dijit.byId("selectPageNumber");
or
var select = this.selectPageNumber;
but I always have select being undefined.
What am I doing wrong?
UPD:
The problem with element has been solved spontaneously and I didn't got the solution. I used neither dojo.addOnLoad nor widgetsInTemplate : true, it just started to work. But I have found the same problem again: when I added another tag I can't get it!
HTML:
<select class="ctrl2" dojotype="dijit.form.ComboBox" dojoAttachPoint="selectPageNumber" id="selectPageNumber">
</select>
<select class="ctrl2" dojotype="dijit.form.ComboBox" dojoAttachPoint="selectPageNumber2" id="selectPageNumber2">
</select>
widget:
alert(this.selectPageNumber);
alert(this.selectPageNumber2);
first alert shows that this.selectPageNumber is a valid object and the this.selectPageNumber2 is null.
widgetsInTemplate is set to false.
all the code is within dojo.addOnLoad()
dojo.require() is valid
I am using IBM Rational Application Developer (if it is essential).
WHY it is so different?
Based on your syntax, I am assuming that you are using 1.6. Your question mentions template and postCreate, so i am assuming that you have created a widget that acts as a composite (widgets in the template).
Assuming 1.6, in your widget, have you set the widgetsInTemplate property to true. This will tell the parser that your template has widgets that need to be parsed when creating the widget.
http://dojotoolkit.org/documentation/tutorials/1.6/templated/
I would remove the id from the select. Having the id means that you can only instantiate your widget once per page. You should use this.selectPageNumber within your widget to access the select widget.
If you are using 1.7 or greater, instead of setting the widgets widgetsInTemplate property, you should use the dijit._WidgetsInTemplateMixin mixin.
http://dojotoolkit.org/reference-guide/1.8/dijit/_WidgetsInTemplateMixin.html
Depending on when dijit.byId() is being called, the widget may not have been created yet. Try using dojo.addOnLoad()
dojo.addOnLoad(function() {
var select = dijit.byId("selectPageNumber");
});
I came close to the solution: it seems like there is a some sort of RAD "caching" that doesn't respond to changes made in html code.
Ways to purge the workspace environment with RAD (based on Eclipse) might be a solution.

Yii Retrieve and store in a variable a renderPartial file

I have a php file under protected/views/directory_controller_name with formatting like that
<p>
<?php echo $model->title;?>
</p>
...
I display the file with classic method in the controller :
$this->render('filename',array('model'=>$model));
But know, I need to send an email with the same template/layout so I want to store the render of the file in an variable like
$msgHTML = $this->renderInternal('_items', array('model'=>$model));
But it doesn't work!
How can I get render view from a file and store in a variable?
Is it possible?
I don't want to use:
$msgHTML = '<p>'.$model->title.'</p>'
...
Because the file is very long and I don't want to duplicate code!!!
Don't use the renderInternal method, use renderPartial instead. Render internal is low level method and should not be used in such context. To catch the output just set the $return parameter to true:
<?php $output = $this->renderPartial('_subView', $dataArray, true); ?>
$msgHTML = $this->renderInternal('_items', array('model'=>$model), true);
http://www.yiiframework.com/doc/api/1.1/CBaseController#renderInternal-detail
I might be missing something, but can't you just use regular render() with the return argument set to true? Then you can just use a view 'name' instead of knowing the path. (And unless my trusty stack trace logger is broken, renderFile and renderInternal take the same fully qualified path argument. At least I can see renderPartial() passing the full path to my view file to renderFile.)
you can do this with these ways
1) if you want to get the output with header and footer (i.e ) full layout then do this
//add true in the last parameter if you want a return of the output
$htmloutput=$this->render('_pdfoutput',array('data'=>'nothing'),true);
2) similarly if you don't want to get the layout files just use renderpartial in the same way
$htmloutput=$this->renderpartial('_pdfoutput',array('data'=>'nothing'),true);
you will get the html of files in the variable . use this anywhere

Drupal: How to get deeplink to comment?

I need to build and print a deeplink to any given comment. So that the user can directly access the specific comment with just clicking a link. I could not find a native drupal function to get this so i build it my own.
My solution
<?php
global $base_url;
$base = drupal_lookup_path('alias',"node/".$node->nid);
$path = $base_url.'/'.$base.'#comment-'.$comment->cid;
$link_options = array('html'=> $html);
$commentlink = l($date, $path, $link_options);
?>
To print the link you only have to call <?php print $commentlink;?>. But i'm pretty sure there is better and much more drupal like way to solve the problem.
The Better Way
Mikeker did it :) As he suggested here are the solution.
<?php
$commentlink = l(
$date,
"node/$comment->nid",
array("fragment" => "comment-$comment->cid"));
?>
Note the little difference bettween Mikeker and my version. array("fragment" => "comment-$comment->cid")); and array("query" => "comment-$comment->cid"));
The query param will add an ? to the url. So your path looks like
//…query
http://example.com/path/to/node?comment-2
In opposite to my solution (fragment):
//…fragment
http://example.com/path/to/node#comment-2
Note:
Do not include the leading '#' character to a fragment identifier. It will be added by drupal.
That's basically the way to do it. Comment permalinks are in the form of:
node/<nid>#comment-<cid>
Where <nid> and <cid> are the node and comment IDs, respectively. You can save yourself a step by not doing calling drupal_lookup_path() -- l() or url() do it for you. The shortened routine would look like:
$commentlink = l(
$date, // Text of the link
"node/$node->nid", // path to node, l() handles aliases
array('query' => "comment/$comment->cid"), // fragment to specific comment
);
In case anyone was wondering, the Drupal 7 way (at least, appears to be) this:
<a href='http://YOURSITE.com/comment/CID#comment-CID'>link text</a>
For example:
print "<a href='/comment/$comment->cid#comment-$comment->cid'>text here</a>";
And this would be placed in, perhaps, a comment.tpl.php file.