Grandioso Posted October 29, 2010 Share Posted October 29, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/ Share on other sites More sharing options...
Grandioso Posted October 30, 2010 Author Share Posted October 30, 2010 Oh, come ooooon. Nobody ? Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1128417 Share on other sites More sharing options...
thehippy Posted October 31, 2010 Share Posted October 31, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1128616 Share on other sites More sharing options...
Grandioso Posted October 31, 2010 Author Share Posted October 31, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1128746 Share on other sites More sharing options...
thehippy Posted November 1, 2010 Share Posted November 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1128809 Share on other sites More sharing options...
Grandioso Posted November 1, 2010 Author Share Posted November 1, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1128943 Share on other sites More sharing options...
Grandioso Posted November 1, 2010 Author Share Posted November 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1129008 Share on other sites More sharing options...
Grandioso Posted November 1, 2010 Author Share Posted November 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1129037 Share on other sites More sharing options...
Grandioso Posted November 2, 2010 Author Share Posted November 2, 2010 OK, I'm done with cake. Shit almost drove me crazy. Moving on to CodeIgniter. Quote Link to comment https://forums.phpfreaks.com/topic/217199-cakephp-n00b-questions/#findComment-1129378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.