Jump to content

Recommended Posts

Hi guys. I'm learning cakePHP and I (will) have a couple of stupid questions.

 

So first of all, how do I add a "selected" class to a menu item that points to the current page and how do I create a title for the current page ?

 

I created a default layout, and all the pages. Then I created the routes in 'app/config/routes.php' like "Router::connect('/contact', array('controller' => 'pages', 'action' => 'display', 'contact'));". It works just fine, but I have no idea how to add "selected" to the currently selected menu item and how to create a custom title for the page.

 

It would be great if I could just pass the "title" and "selected" string in this array.

Is it possible ?

Link to comment
https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/
Share on other sites

how do I add a "selected" class to a menu item that points to the current page

I'm not sure what your intended meaning of the question is.  Are you trying to add a CSS class to some menu item?  Are you trying to make a breadcrumb trail? Cake controllers all have a name attribute, is that what you're asking for?

 

how do I create a title for the current page ?

Two ways, you can pass a title how you normally would pass data to a view, using the set() method and having the corresponding echo in your view.  Alternatively and more commonly, if you use layouts you can set the pageTitle attribute in your controller.

I did a lotta search on this, but I didn't find any reasonable solution.

 

All I want to do is have urls to static pages like : www.domain.com/mypage and the 'mypage' item highlighted in the navigation and the title to be 'My Page' (just an example).

Now I could do this just by putting my .ctp files in the 'pages' folder, but the the urls would be like : www.domain.com/pages/page.

So I created custom routes. It works, but I want to perform a custom action (set the page title and a variable) before the page renders.

I figured I could customize the default "Pages" controller, but it doesn't work  >:(

I create the appropriate methods, they run just as they should, but they don't send the page title like they should.

 

I don't believe that such a primitive task can be so complicated. D'OH.

 

 

//edit

allright now, the page title works.

I just need to figure out how can I set a variable in the controller and read it in the layout without having a model.

As soon as you start needing to change data on the fly your content is no longer static and supercedes the purpose of the built-in pages controller.

 

Make your own controller, disable autoloading of a model (var $uses = array();), set your layout, set your title and your 'selected' menu item in the controller's action.  Then use php to build your menu directly in the view, or since it'll most likely be a reused piece of code create an element (sub-view) to do it for you.

 

I suggest you put off the routing aspect until you have the functionality you want, when you're done changing the route isn't that big of a deal.

I already solved this, but I've got more questions.

 

I want to create a model to a DB table in which there are columns with not just single word titles. The column titles contain non-english words and some of them are two words (I would create them with an underscore between the words).

 

Does automagic cover this ? ('this' meaning it can convert underscores to spaces a non-english characters to english ones (like č to c, š to s)).

 

Then another one : what happens if I don't follow the naming convention ? I have a database table and I need to assign it the model, view and controller. How do I do this ?

Now I have an encoding issue. Table sorting is set to utf-8_slovak_ci and all table cols' encodings are set to utf-8_slovak. But when I read from the database and output it on the page, I get qmarks and other weird characters instead of slovak special chars.

 

Cake's core.php says :

Configure::write('App.encoding', 'UTF-8');

 

Where's the problem then ?

 

//got it, I didn't know I had to specify it also in database.php

I've encountered another problem. I've created my model, controller and view for my DB table not following the naming convention. I've successfully set the model to use the table, but when I create a form in the view, it is given the wrong action parameter.

 

So how do I set which controller should handle my form from the view ?

I can't follow the naming convention, because the app is not in english.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.