CakePHP 2.5 Theme and layout not loading - cakephp

I'm trying to use themes with CakePHP 2.5.X and I'm failing to load the theme and associated layout inside that theme. What I've done is create "app/View/Themed/Hamilton", and within that directory I've created, "View/Layouts/default.ctp". In "app/Controller/AppController.php" I've done this:
public $viewClass = 'Theme'; /* I've tried $view, it does not work. */
public $theme = 'Hamilton';
public $layout = 'default';
Sadly it loads "app/View/Layouts/default.ctp", not "app/View/Themed/Hamilton/View/Layouts/default.ctp"
I've search stack overflow, no article that talks about this has an answer that works. All debug outputs the proper layout, theme, etc. I've checked spelling and case. It just simply is not loading. Anyone have a fresh perspective?
UPDATE: And once I ask the question I find the solution. The path was wrong to the layout. It should be "App/View/Themed/Hamilton/Layouts/default.ctp" there does not need to be another "View" folder.
Hopefully this may help someone else who has the same issue.

According to the docs, the Layout should be in /app/View/Themed/Example/Layouts/, so in your case it is /app/View/Themed/Hamilton/Layouts/default.ctp, not app/View/Themed/Hamilton/View/Layouts/default.ctp as you said.

Related

displaying multiple ascx in dotnetnuke

I am a newbie programming modules for dotnetnuke.
At this moment I use only the view.ascx for displaying my logic.
I need to display different views based on the login user and the attach user role. I can do it by setting some of the controls visible and non visible but I think it is not the right way and make the code unnecessary complex.
I came across an earlier question in stackoverflow (DNN: Using multiple web user controls in one module and showing different controls in different pages)
But have still some questions:
I have to add a new webformuser control in vs2013 when I want to design a new view in a seperate ascx?
I think the solution mentioned in the link using a placeholder will solve my question. But which steps do I need to transform my current solution with "view.ascx" to a solution with a placeholder?
I need to create first a new webusercontrol and named it "MasterControl.ascx" and put the placeholder control in it?
I need to create additionally for each view a new webusercontrol? What about the view.ascx? I dont need it anymore? What is the controlpath? Is it the path where the user control reside?
Is this the following layout:
MasterControl.ascx calling
userview1.ascx
userview2.ascx
...
userviewk.ascx
How to register "MasterControl.ascx"? I dont see "add control" in my current module when edited? I used DNN 7.2.x with the Cristoc addin.
I have to replace child1 wirh userview1 etc? When I supply the condition the corresponding userview.ascx will be displayed?
I a am a complete newbie so I need a step by step "cookbook recipe" how to convert my current module with, only using, a one "view.ascx" approach with a more flexible multiple ascx solution.
Thanks in advance,
Regards,
Henk
a copy of the code mentioned in the above link.
string childControl;
switch (condition)
{
case "condition1":
childControl = ControlPath + Child1.ascx";
break;
case "condition2":
childControl = ControlPath + Child2.ascx";
break;
...more conditions...
}
PortalModuleBase objModule = (PortalModuleBase)this.LoadControl(childControl);
if ((objModule != null))
{
myPholder.Controls.Clear();
objModule.ModuleConfiguration = this.ModuleConfiguration;
myPholder.Controls.Add(objModule);
}
If you only have a few things to hide or show then you could make use of <asp:Panels>. You could the set the visibility depending on a calculated property or some other logic; for instance, I have used the IsSuperUser property.
ASCX file:
<asp:Panel id="pnlSomeDeclarativeCode" runat=server>
<h1>Hide or show me</h1>
</asp:Panel>
In your codebehind file:
private Initialise()
{
pnlSomeDeclarativeCode.Visabilty = UserInfo.IsSuperUser;
}

CakePHP default layout for xlsx

I have a method which exports riport data into an xlsx file in my CakePHP 2 project. It is working well. In the same time it seems it just ignores anything what I put into View/Layouts/xlsx/default.ctp
In my routes.php I have
Router::parseExtensions('json', 'xlsx');
In my controller I have
public $components = array('RequestHandler');
My View/Riports/xlsx/export.ctp is rendered, but View/Layouts/xlsx/default.ctp is ignored.
What do I miss?
I think you're out of luck here. From the documentation;
The data view classes don’t support layouts. They assume that the view file will output the serialized content.
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#using-a-data-view-with-view-files
But I may be wrong of course :)

Does CakePHP DebugKit have built-in support for changing the toolbar location?

I'm enjoying using CakePHP's DebugKit toolbar, but is there a simple way to change its location from top right to anywhere else on the screen without having to fiddle with the code?
If the answer to this question were as simple as changing the CSS from top:0px; to bottom:0px; for #debug-toolkit-bar, I'd have already done it and I wouldn't be asking a question in the first place. The answer definitely isn't documented in the ever-so-hefty 9k readme.md file found on github unless you're referring to the section on Toolbar Configuration Settings:
The toolbar has a few configuration settings. Settings are passed in
the component declaration like normal component configuration.
public $components = array(
'DebugKit.Toolbar' => array(/* array of settings */) );
That's all it says about the "array of settings" - not much help there.
It does not have built-in support for changing it's location.
OP: If the answer to this question were as simple as changing the CSS from
top:0px; to bottom:0px; for #debug-toolkit-bar, I'd have already done
it and I wouldn't be asking a question in the first place.
It is actually that simple. To change it's location, just look at the CSS for the debug-kit-toolbar and the panel-tabs and override the float-lefts to right and the position to left instead of right...etc - all simple CSS stuff.
As far as the settings, you can view any/all of it's settings by looking at the code for the DebugKit Toolbar in Github.

Drupal 7 not using the template suggestion

I have added the following to my template.php file, in the [themename]_preprocess_page function:
<?php
if ($variables['is_front'])
{
$variables['theme_hook_suggestions'] = array();
$variables['theme_hook_suggestions'][] = 'page__index';
}
if (isset($variables['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $variables['node']->type);
}
If I run a var_dump on the $variables array, I can see that, on my front page, the 'theme_hook_suggestions' is set to only use 'page__index'. I have a file named 'page--index.tpl.php'. Drupal still uses page.tpl.php.
I also commented out the code above, and renamed the file to 'page--front.tpl.php' and it still used page.tpl.php. I clear the caches after every change.
What am I missing?
Edit: To help clarify, I want to override the entire design of the page for the front - no columns or sidebars, different graphics, different backgrounds on some of the div's, etc. I don't want to override the 'node--' template files (yet).
In the end, I need to have a static front page with a different design than the rest of the site, then a custom node template for each content type.
I worked with the awesome folks on the #drupal IRC channel and found the issue. Not sure if this is a bug in the code or on purpose - but you cannot use the word 'index' for those theme suggestions. I changed the content type's name to 'homepage' and voila!

How to use default.ctp in cakephp

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.

Resources