I want to be able to create a magnet link using CakePHP's Html Helper. How would I go about doing that?
I've already tried something like:
<?php
echo $this->Html->link($name, 'magnet:.....');
?>
My point: CakePHP sees anything that does not start with 'http://' as a relative URL. At least that's what the manual states.
Of course I could go and hammer (filter) out the 'http://' after having put it there before the 'magnet'-part.
But is there some (better) way for this without resorting to non-CakePHP-assisted HTML code?
You're forcing something that you don't need to do. The largest draw to using Cake's $html->url() function is to quickly and easily generate dynamic urls that work with Cake's routing. That has little to do with magnet urls. I'd say just go old-school here.
<a href='magnet:<?php echo $magnet_url; ?>'>Magnet Link</a>
Related
The standard ("ships with Drupal") user page appears to be compacted into the $user_profile() array. Then, it's unpacked and "printed" (to the screen) by the somewhat terse user-profile.tpl.php template:
<div class="profile"<?php print $attributes; ?>>
<?php print render($user_profile); ?>
</div>
Is there a guide somewhere that would help me understand what the typical internal structure of this array is, and what hooks I might need to employ in order to place DIVs, classes and so forth into it, in order to achieve certain basic design goals?
Take a look at https://drupal.stackexchange.com/questions/88407/how-to-create-a-profile-page. I strongly suggest to use the Panels module. It allows you to add blocks, views etc. to your pages and makes theming a lot easier. There are tons of information about Panels on the internet, so I suggest you have a look around first. The following links can be a good start:
https://www.drupal.org/node/496278
https://drupalize.me/search?query=panels
Is possible to change pagination url names in cakephp?
For example:
example.com/tests/act/page:2/sort:title/direction:desc
to:
example.com/tests/act/pg:2/link:title/orderby:-date
Thank you all. But I am beginner in cakephp and pleased to see an example.
I read the documentation. but there is nothing about things I want.
Maybe I can translate those parameters and give to the Paginator class. but how?
Yes. Use routing. http://book.cakephp.org/2.0/en/development/routing.html
Just create a rewrite rule for it.
Pagination Works with named parameters, and there is not a simple way to rename them. You will need to modify the PaginatorComponent and PaginatorHelper to modify the parameters of the pagination.
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.
I just finished the "15 min Blog Post tutorial" included in the documentation for cakephp. I was asked for another tutorial to change the layout for first tutorial.
However, I am fairly new to MVC programming/Cakephp and I have no real clue how to do so. Well, I know I need "default.ctp" placed in app/views/layouts/ and I presume I need to include
to include my data? . . .
I am really at a loss of what to do. I set up my default.ctp as I mentioned above, but when I go to localhost:9999/posts the layout is still the same. I guess I need to include a stylesheet (and if so, where?)
I guess if someone can point me in the right direction to a beginner's guide to layout styling or how to use it I would greatly appreciate any help.
I would advice you to read the following from the cookbook: Layouts and CSS. Then copy the layout from /cake/libs/view/layouts/ to /app/views/layouts/ and modify it to your needs. After that create you stylesheet (or modify existing one) in /app/webroot/css/ and include it in your layout.
Create in app/View/Layout a file named "my_posts_layout.ctp"
In your PostController set $this->layout = 'my_posts_layout';
This way you should view the content defined on my_posts_layout.ctp.
Lack of stylesheets has no impact here.
How MVC works in CakePHP:
The router dispatches an incoming request to an appropriate Contoller.
The appropriate Controller function executes (no output, just fetching data, setting up variables).
The appropriate view is rendered. In fact, the output of the view is just contained in $content_for_layout.
What you really get back in the browser is in the layout. Therefore you can put your view's output into the layout by echo $content_for_layout in default.ctp. (Of course you can also have different layouts.) In addition, the layout can be enhanced with elements.
I really recomend the CakePHP CookBook, easily found from the CakePHP homepage. Modifying default.ctp should edit your applications layout.
A more specific question (eg. code samples of your default.ctp, expected results etc) might help people provide a better answer than mine.
What is the best way to create regions in your layout similar to Wordpress's Widgets or Drupal Blocks? What is the best practice method of doing that in CakePHP?
If by regions you mean a special "content container" (never used WP/Drupal), then it's very easy.
There are several ways to accomplish this, but the one that came to my mind first was this:
Create a helper (or an entire plugin) to handle the "which content goes into which container" logic. Shouldn't be too hard to do because you have many Cake utility classes to help you out with that (such as the Configure class). This should obviously be configurable by the end user.
Create containers in your layout, example:
<div class="content-container" id="content-container-left">
<?php echo $yourHelper->outputContent("left"); ?>
</div>
Two options:
Content should be based on elements; or
Content should be based on custom plugins (which actually do their stuff and output the content)
Note: There are probably better ways to accomplish what you want, this is just the first that came to my mind. I'd recommend some pencil-and-paper planning before you actually code anything, it will improve your chances of finding the best way for your app.
I created a Sidebar Helper recently that you might find useful.
You define the content of the boxes in Cake elements, and then add them by calling ...
$sidebar->addBox(array('element'=>'my_sidebox_element');
... this would render the content of views/elements/my_sidebox_element
Alternatively you can specify te content of a box 'inline':
$sidebar->startBox(array('title' => 'My Inline Box'));
<p>blah <b>blah</b> <span>blah</span></p>
$sidebar->endBox();
The in your layout file call
echo $sidebar->getSidebar();
... and each of your boxes will be rendered as divs
Technically speaking this doesn't need to be used as a 'SideBar' - it ultimately depends on how you render the layout with CSS.
See the documented code for more details:
SidebarHelper on GitHub