![]() |
Set different page title for every other page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9) +--- Thread: Set different page title for every other page (/showthread.php?tid=934) |
Set different page title for every other page - wiyono - 01-30-2015 Can somone help me how to set different page title for each page? i am new with codeigniter and i make my website with the tutorial from codeigniter, but i am confused how to make title page for each page, maybe from controller or so? thx for your help Wiyono RE: Set different page title for every other page - wiyono - 01-30-2015 ooh, no aswer? please help me ;-) RE: Set different page title for every other page - CroNiX - 01-30-2015 Yeah, you just pass data from your controller to your view. Code: //controller RE: Set different page title for every other page - wiyono - 01-30-2015 Hey CroNiX, thx for your answer, that's mean i have to make each controller for each pages? ohye, can i make only one controller for all page or so? thx again for your answer? Regard Wiyono RE: Set different page title for every other page - mwhitney - 02-02-2015 You could handle this any number of ways. What I usually do is set a default page title in my controller's constructor, then change the title as needed in the controller's methods (in most cases, the methods just add something to the title set by the constructor, since all of the pages served by a controller are usually related). Then I use a function to load my data into my view and call it from all of the controllers, so I can get some defaults if I forget to set something in a given method or don't want to repeat certain things in each method. For example: PHP Code: class News extends MY_Controller RE: Set different page title for every other page - wiyono - 02-02-2015 Hey mwhitney, thx for your help i have solution like this PHP Code: class Pages extends CI_Controller { PHP Code: function about-us() { Thx again Regard Wiyono RE: Set different page title for every other page - CroNiX - 02-02-2015 You can't have a dash in a function/class/method name. To PHP, that's subtraction. Basically you create a route, using the dash, that routes to whatever controller/method, but the method name must be legal PHP. Code: $route['about-us'] = 'controller/about_us'; //Sends 'about-us' request to the controller/about_us controller/method with the underscore Controller method: Code: function about_us() Code: <a href="/about-us">About Us</a> //clicking will actually go to "about_us" behind the scenes due to our route RE: Set different page title for every other page - wiyono - 02-04-2015 Hey CroNiX, thx for your answer, unfortunately i got error 404 page if i make the router like that, then i call about-us page. Can you help? what i did wrong? Thx Regard Wiyono RE: Set different page title for every other page - CroNiX - 02-04-2015 post your route and the controller (not just the method) RE: Set different page title for every other page - wiyono - 02-05-2015 Hey CroNiX.... yeeeeeeeeezzzz... thank you so much... i forget to change the controller with the name of controller... thank you again. Regard wiyono |