CakePHP 2 with CakeDC/I18n language prefix being lost - cakephp

I have a CakePHP 2.5 site running with CakeDC/I18n plugin to allow for multi language support. I have installed the plugin to use a 3 letter prefix when switching languages:
www.example.com/eng/
This is working fine when I click a button to change languages. The language prefix is added to the url. The problem is when I switch pages by clicking on a link the prefix is dropped. Why would this be happening? Do I need to do something in the href markup? My understanding is that the CakeDC/I18n plugin would take care of this.
Any help would be greatly appreciated as I have been scratching my head with this one for awhile!

You need to pass as parameter the current language.
Otherwise it'll always use the default language that you defined in the bootstrap.php
Here is an example.
Router::url(
'lang' => 'spa',
'controller' => 'articles',
'action' => 'view',
'slug' => 'test'
);

Related

Selector for input checkboxes Drupal 7

I am trying to hide a field based on what user is selecting from a entity referenced checkbox list but no matter what I do I cannot hide the field.
I think some issue with the selector.
$form['title']['#states']['invisible'][] = array(
'input[name="field_offering_course[und][0][target_id]"' =>array('checked' => TRUE));
You are missing a bracket:
'input[name="field_offering_course[und][0][target_id]"]' =>array('checked' => TRUE));
I can't help more than that...not very experienced in php :D

how do I use the data in array in joomla list view as a link

I have the following code " which is not quite correct" in a part of a list view in my component. For Joomla 3.4
<td style="text-align:center">
<?php echo JDom::_('html.fly', array(
'dataKey' => 'link',
'dataObject' => $row,
'href' =>array($row->link),
'target' => '_blank'
));?>
I am trying to get the link from the field called link , but every thing I have tried either places the sites url before the link, does nothing or just goes back to the front page of the site. The link field contains a link to another website.
Can someone help me with this code snippet?

How to change url pagination in cakephp?

I want my url to change from this
/examinations/getchoices/page:2
to this
/examinations/getchoices/item/2
I wonder how to do this. I've already tried changing in the routes.php. I've tried the tutorial in this site. The page content doesn't change when I click prev or next links.
This is what i got in the url
/examinations/getchoices/ 2/ 2
My version of cake is 2.1.
Your help will be much appreciated. I've been stuck with this for 2 days already. Thank you.
You can define custom routes.
http://book.cakephp.org/2.0/en/development/routing.html
e.g.
Router::connect(
' /examinations/getchoices/item/:number',
array('controller' => 'examinations', 'action' => 'getchoices'),
array('pass' => array('number'))
);
let me know if i can assist you more

How should I handle forms in CakePHP?

I'm studying CakePHP. I read a CakePHP book, and web tutorials, but I still don't get some basic things:
I see people always create a form in View with $form->create. Can I use an HTML form like normal, or must do exactly like people do?
When a form is created in login.ctp with this code:
echo $form->create('User', array('method' => 'POST', 'action' => 'login'));
echo $form->input('email');
echo $form->input('password');
echo $form->input(array('type' => 'submit'));
echo $form->end('Login');
When I click the submit button, will the data be passed to the function login() in the Controller class?
Edited :
I tried this :
<?php
$this->Form->create("Test");
$this->Form->input("stuId",array('class'=>'inputField', 'placeholder'=>'SVxxxxxxxx'));
$this->Form->input("stuName",array('class'=>'inputField', 'name'=>'stuName'));
$this->Form->end();
?>
But it show nothing ? what is the problem :(
But it show nothing ? what is the problem :(
You have to use echo as in your first code snippet:
echo $this->Form->create("Test");
echo ...
You can use HTML for anything you want, but you'd be losing a big advantage of the CakePHP framework. The Cake HTML and form helpers help to future-proof your code. You also get the benefit of Cake's implementation of best practices in web coding. I fully recommend using those helpers.
The form data is passed to $this->request->data.
Yes, the parameters will be passed to login method.
I see $form being used in the form there, it appears you are using older version of cakephp (if $form has been instantiated with $this->Form then you are fine)
The FormHelper does lot of automagic for us and it also provides us means for added security.
I would reckon you to go with The Blog tutorial

Drupal 7: Modifying menu HTML output?

I am trying to modify the HTML output in a Drupal 7 theme that I am creating.
Basically, instead of the < li >s containing just plain < a >s with text, I want to include some additional HTML inside the < a >.
I know that it's possible to modify the HTML created by the menus in Drupal. I can see the following call in page.tpl.php:
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t(''),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
which apparently calls the theme function, which creates the output. One way to modify the output would be to modify the theme_links function in theme.inc, right?
http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links
I also know that you can put a hook in template.php to override the function which creates the HTML. I can't figure out how to create the actual override function. Can somebody point me in the right direction, please?
What you would do is implement a hook to modify the output, not modify the "theme.inc" file directly.
For example, the accepted answer on this page: Drupal Override Custom Menu Template
And as a general rule, when you want to modify the output of something, either implement a hook (in a module or in the template.php of the active theme) or use a template with a predefined file name when such a case exists (when no template already exists, you can also modify the list of template suggestions using a module or the theme).

Resources