Cakephp view not working - cakephp

When I want to see for example localhost/pages/index, the localhost page is shown. The controller is working (the debug shows proper value defined in the controller). Also the title of the localhost/pages/index is set properly ("Posts"). Can somebody help me?
The page is in /app/View/webroot
Also, the view is working, when die() inserted in the end of index.ctp it is shown properly.

localhost/pages/index refers to a file called index.ctp in app/View/pages
app/View/webroot is for your assets - images, css, js and so on.

Related

angular and ui-router - opening a detail page

I'm sure ui-router is very useful when a site gets complex, but man is it indecipherable on a simple site.
I've got a table with a bunch of records on a summary page called /records/. (not concerned about how this page was built - it's built with ng-grid)
I want to click on record 102 and have it open /records/102 where I will use the id to show deets of 102.
This plunker is never going to work, but I've tried to put the basics in:
http://plnkr.co/edit/qfEaMM8Ihgg8gCUAMHbE?p=catalogue
enter code here
This: {{row.entity['id']}} does give me the record ID I'm looking for - I've got that working. It's a matter of how I get it to routes.js where it says url: '/records/:recId' and then how I get it to appear in the URL when it goes to the new page.
How do I do that?
(P.S. 'Submit Error: links to Plunker must be accompanied by code'. What??)
To redirect to /records/102 you just use a normal html anchor like this:
<a href="/records/{{row.entity['id']}}" ...>
Yo get the value out in your RecordsController you need to use the $routeParams service, inject it and use it like this:
$scope.recordId = $routeParams.recId;

AngularJS set title and description in head when populating content from JSON

Before I go and do this in Jquery out of frustration I figured I would ask what the angular way is?
I'm building an AngularJS site using a model based of the Phonecat tutorial example on the AngularJS site.
I found this method to set the title of a page and can work out how to modify it to do description as well in the app config but this doesn't work when I'm populating pages with content via json. I tried doing it using a ngbind method as well but have yet to find a working solution as I think something to do with the order in which files are loaded is breaking.
For example
when('/faq', {
templateUrl: 'sub_pages/articles.html',
title: 'Landing page title goes here, not to big a deal'
}).
when('/things-to-do/:activityID', {
templateUrl: 'sub_pages/activity-detail.html',
controller: 'activityDetailCtrl',
title: 'If I put a title here it will be the same on all of these pieces of content'
}).
What method can I use in order to set title on both the landing pages and also the pages which draw their content from a JSON feed?
EDIT - ANSWER BELOW
After about 2 days of bashing my head against a wall trying to work this one out it's actually quite simple and works for both static pages and templates with dynamically loaded content.
Inside the view pages (html that loads inside of ng-view) add a couple of divs (you can put this anywhere really) and then inside them you need to load in ng-init.
ng-init="$root.title = path.to.title"
ng-init="$root.description = path.to.description"
This will set the title and description on the root scope. The "path.to." is just an example path to content in json, you can replace this with plain text as well which is how I deal with landing pages.
Then on the index.html or what ever page your app is based on inside the head you just need to load in.
Your Page Title
This will automatically set your page title and description meta tags and you can pretty much use this formula for any other meta data you need to create.
I haven't tested this yet with Prerender.io or any other cache service but will do some checks and post the results here.
Something like
$document[0].title = "xyz";

cakephp v2 layout not loading

Hi I want to add a new layout to my cakephp, but somehow the system keeps looking in the view folder from the controller instead of the /app/View/Layouts folder.
Error: The view for TestsController::desktop() was not found.
Error: Confirm you have created the file: /app/View/Tests/desktop.ctp
the desktop.ctp file is in /app/View/Layouts. The same place as the default.ctp
The code in the controller is:
public function desktop() {
$this->layout = 'desktop';
}
What is wrong here? I don't understand why cakephp keeps looking in the view/controller-name folder... I need this fixed because I want to use this layout for other controllers. Thanks.
If you read the message carefully, you'll see cake is telling you it cannot find your view, not your layout.
So, create an empty /app/View/Tests/desktop.ctp and see what happens. I'm hoping magic.. :)

Experiencing strange behaviour with cakephp

I was setting up this application in cakephp.I have homes controller which works well and then i have chokates controller which has an index action.But whenever i run this chokates controller i get an error
Call to a member function charset() on a non-object
I had a print of $this in top of this controller which shows me that html and javascript helpers are loaded already.Then why i get this error i dont know.
Please help
Here is the link http://www.maninactionscript.com/chokate
go to the chocolates link.
Regards
Himanshu Sharma
Well, looking at your error message it appears that a couple things are happening here that should be fixed:
The view for ChokateController::index() was not found.
Ensure that you have an index.ctp file in /app/views/chokate/.
The HtmlHelper object likely isn't being added to the view because you have a manually configured list of $helpers. If you have assigned an array to $helpers in ChokateController ensure that Html is listed.

Simple examples on how to use CakePHP pages_controller.php to create static pages

I am complete beginner to CakePHP but I am a bit knowledgeable in ROR.
Can somebody pls give me some simple examples on how to make use of pages_controller.php? I want to create static pages such as Home, About, and etc but I don't know how and where to start. I tried something like creating a about.ctp in the views and creating about_controller.php (this is how being done in Ruby on Rails) but I just got some errors.
I concluded that all of the static pages will only use 1 controller which is pages_controller.php but I dont know how.
I tried reading the article found on this link:
http://book.cakephp.org/view/958/The-Pages-Controller
but it doesn't give me anything that will help me learn how to use it.
This is what I got from the page:
CakePHP core ships with a default controller called the Pages Controller (cake/libs/controller/pages_controller.php). The home page you see after installation is generated using this controller. It is generally used to serve static pages. Eg. If you make a view file app/views/pages/about_us.ctp you can access it using url http://example.com/pages/about_us
When you "bake" an app using CakePHP's console utility the pages controller is copied to your app/controllers/ folder and you can modify it to your needs if required. Or you could just copy the pages_controller.php from core to your app.
Can somebody pls show me or explain to me how??? I am a total beginner pls help.
It's pretty self explanatory.
Create a file in your APP/views/pages/ folder - e.g about_us.ctp
Type in your content. No layout; just the text, tables/images/etc
<h3>About my site</h3>
<p>bla bla la</p>
<?php echo $this->Html->image('my_img.jpg'); ?>
Save.
Go to www.site.com/pages/about_us - your page is served.
Pages is the controller to serve static pages. you don't need an about_controller, unless you need something more than just a static page.
You can change how the link looks by using routing.
You can set variables for use in your template as well:
about_us.ctp
<?php
$this->set('title_for_layout', 'My about page');
$this->set('active_link', 'about');
?>
<h1>My page!</h1>
etc

Resources